- Home /
[Unet] NetworkServer can not assign local player authority after a scene change
Hello. So my problem is like the question states.
I use NetworkManager and have inherited the class.
I have a Custom Scenecontroller which tells the local client to send a message to server that the client has loaded. Everytime the game loads a scene, a prefab with networkbehaviour will be spawned. This prefab has a PlayerController class, which holds commands for basic data.
My networkmanager offline scene is the basic fill info and connect scene. Online scene is a lobby where you choose your team. Third scene, which is not included in networkmanager, is the game scene.
I have noticed that when the server uses NetworkServer.ServerChangeScene to load a third scene, in this situation it is the Game scene in which fighting and so on happens, I have to call NetworkServer.AddPlayerForConnection to re assign a gameobject for the player. In this particular moment everything works fine, a prefab with isLocalClient checked will be spawned and I am happy.
But when I use a command from that playercontroller in the gamescene(3rd) scene, it fails to set local player authority. IsLocalPlayer is always false and playerControllerId is -1.
tldr: In a third scene with networkmanager, spawning a playerobject to represent player in the battlefield using a Networkserver.SpawnWithClientAuthority doesnt work. PlayerController is only a helper class to help find needed functions and variables.
[Command] public void CmdSpawnPlayer() { TryToSpawnPlayer(); }
void TryToSpawnPlayer()
{
if (!NetworkServer.active) return;
Vector3 start = new Vector3(14, 6, 20.3f);
GameObject go = Instantiate(PrefabController.instance.GetPrefabFromDictionary("InGamePlayer"), start, Quaternion.identity);
NetworkServer.SpawnWithClientAuthority(go, connectionToClient);
}
I have tried DontDestroyOnLoad on every playercontroller object, but same result. The third scene just doesnt give player authority. No errors are displayed.
Your answer
![](https://koobas.hobune.stream/wayback/20220612143644im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
NetworkBehaviour.isClient problems 1 Answer
How to watch in client applications what it is happening in the server one? 0 Answers
Very Confused on Networking HLAPI Practices 1 Answer
Since switching to using offline & online scenes in the NetworkManager, Clients will not sync (UNET) 0 Answers
Unity Network, smooth interaction between client and server player objects 0 Answers