#Setting up the Start Position results different each time
94 messages · Page 1 of 1 (latest)
It is set to Round Robin
It actually does the work, it sets the transform to start point but it immediatly changes to Vector3.zero again. Its like sets the position to StartPoint and 1 frame later sets back to Vector3.zero
But sometimes it skips that 1 frame and accepts the start position which i've set in the code
@coral wraith
You're not overriding OnServerAddPlayer, correct?
No i only override that function inside my customnetworkmanager and in lobby scene only
you can see it in the code up above pastie.io link
You need an else in OnServerAddPlayer:
if (SceneManager.GetActiveScene().name == "Lobby-Scene")
...
else
base.OnServerAddPlayer(conn);
And delete lines 40 and 42
And move line 41 to ThirdPersonController::OnStartLocalPlayer on the player object shortened to:
PlayerState = PlayerState.MOVEMENT;
I'd say get rid of this too (line 13)
GamePlayerInstance.ConnectionID = conn.connectionId;
all Network Behaviours have connectionToClient built in, so you don't need the redundancy
okey done that
now trying
Nope, still teleports me to the Vector3.zero position
do i need a network identity component on those ?
@coral wraith
Why you setting autoCreatePlayer = false; ??
show inspector of player prefab with all components folded up closed so I can see what's on it
here sir
Disable these 3 in prefab and enable them in OnStartAuthority or OnStartLocalPlayer in your PlayerObjectController script. Also make sure RigidBody is kinematic in the prefab, and set that false in OnStartAuthority / OnStartPlayer only if you're using AddForce on it
I did what you wrote but didnt work i think because PlayerObjectController is instantiated on lobby scene , not in game scene . So if i override OnStartLocalPlayer or OnStartAuthority those will be called in Lobby scene not when game starts.I think you want me to enable them when game starts if i correctly understood
Just add a scene check in there if you're using same prefab for lobby and game
I did but OnStartAuthority and OnStartLocalPlayer not fired when scene is changed, they only fired in Lobby scene when i instantiate
I Have my auto create player ticked on, i've added a debug log statements for the both functions i didnt get any prompt
This is from our PlayerController:
[RequireComponent(typeof(CapsuleCollider))]
[RequireComponent(typeof(CharacterController))]
[RequireComponent(typeof(NetworkTransformReliable))]
[RequireComponent(typeof(Rigidbody))]
public class PlayerController : NetworkBehaviour
{
protected override void OnValidate()
{
base.OnValidate();
Reset();
}
void Reset()
{
if (characterController == null)
characterController = GetComponent<CharacterController>();
// Override CharacterController default values
characterController.enabled = false;
characterController.skinWidth = 0.02f;
characterController.minMoveDistance = 0f;
GetComponent<Rigidbody>().isKinematic = true;
this.enabled = false;
}
public override void OnStartAuthority()
{
// Add Scene Check here if appropriate
characterController.enabled = true;
this.enabled = true;
}
public override void OnStopAuthority()
{
this.enabled = false;
characterController.enabled = false;
}
}
They won't if you put the lobby player in DDOL...
yes its DDOL
does it need to be?
It would turn my week to hell if i need to remove it from DDOL
Can i achieve my goal if its in DDOL ?
what are you changing in the player in the lobby that you need to carry it through?
PlayerObjectController script, where i get steam datas like username etc.
Wouldn't all that still work if the player was respawned?
Steam Manager or whatever is in DDOL, so it's still available
if script values gets saved in despawning and respawning then it will work
oh yea i am holding their values in GamePlayers list
centralization - the bane of networking
if that's a static list that doesn't get cleared
its not a static list but a list in custom network manager
so i dont think it gets cleared
but how would i know which player's value is which if i dont have any value about a player upon respawning?
Typically you'd keep player data on the player or in the connection, instead of centralizing, but if you can't easily unwind that, then you having player in DDOL really should've come up sooner. Everything I told you didn't consider that.
So your original post about Start Positions not working was a red herring. Your real issue is snap-back when force moving players with NT after scene change.
Yes i am sorry because of misleading you and couldnt address my issue properly
My issue is exactly it is
Ok so if it's in DDOL, you can try this first....
In OnServerReady, inside the "Level-1" scene check:
Transform startPos = GetStartPosition();
NetworkTransformReliable nt = conn.identity.GetComponent<NetworkTransformReliable>();
nt.RpcTeleport(startPos.position. startPos.rotation);
And in PlayerObjectController you'll have to enable your components in OnClientSceneChanged, wrapped in the same scene check, since OnStartAuthority / OnStartLocalPlayer only run when first spawned
@twilit horizon
doing that rn
PlayerObjectController is derrived from NetworkBehaviour, did you mean OnClientSceneChanged in CustomNetworkManager?
there is no suitable override in PlayerObjectController for OnClientSceneChanged function
oh right...yes
NetworkClient.localPlayer.GetComponent<PlayerObjectController>().EnableComponents();
And in EnableComponents you can turn things on by reference you set up at design time
implementing rn give me couple mins pls
I always have treated the lobby player as an empty prefab that just does UI stuff in the lobby scene and is disposable, and game player prefab is separate. Anything I'd need to carry forward is either in a database or a struct in conn.authenticationData
I need to leave for meetings...back later
Yes it still keeps happening i couldnt resolve, i think i just need to do what you do usually, which is treat as a empty prefab and spawn a player on scene
Hello again, i managed to solve issue like this but i am not sure if its the best practice, I know only instantiate a lobby object where i hold the steam data and when i switch the scenes i instantiate a player object and replace the connection
But know issue is that since client doesnt have any authority on created player, i cant move the player from server or from client side, How do i assing an authority i've tried AssingClientAuthority function from network identity but it still doesnt work
@coral wraith
If you're using AddPlayerForConnection or base.OnServerAddPlayer the owner client gets authority - you don't do anything extra
i use ReplacePlayerForConnection
That also grants authority
But if i Debug.Log(authority) or Debug.Log(isLocalPlayer) both of them returns false on spawned object
When are you doing that? OnStartAuthority / OnStartLocalPlayer is what you want (they only fire when true)
i basically do that inside Update() but i watch for 20-30 seconds if it turns true or still false
I assume you mean isOwned or isLocalPlayer
Yes
Are OnStartAuthority / OnStartLocalPlayer overrides firing on client?
on server you're seeing host client firing those...server doesn't fire those
is this latest ^
lines 60-65 don't belong in OnServerReady. Probably OnClientSceneChanged with a scene name check, and you'll need a name from someplace (I think you can get display name from steam on client).
line 40, it's better to do GetStartPosition before instantiate and use it in Instantiate instead of moving it
trying it out
this is the current code i've send link with paste.io
Positions are correctly set but the thing is that server can move its own character but client cant
this is the boolean check for movement maybe its because of isLocalPlayer returns false?
Nevermind its completly unreleated problem with Mirror, Somehow unity's player input script was randomly changing controller schemes, for server it sets keyboard-mouse but it set for client x-box now i changed auto switch and set default scheme.Problem solved
Thank you so much for your help, i took too many from your precious time.But as always you are a super good helper.I hope one day i can pay back the help in any way
Made some revisions to simplify this a bunch...read carefully before using it. https://pastie.io/lekdvd.cs
edited ^