private void OnServerAddPlayer(NetworkConnection networkConnection, short controllerId)
{
var go = (GameObject)Instantiate(_vehicle, _spawnPoint.position, _spawnPoint.rotation);
NetworkServer.SpawnWithClientAuthority(go, networkConnection);
}
So “hasAuthority” on that new gameobject is always false on host, but true on clients connected to the host.
I know that this is an expected behavior as stated in http://docs.unity3d.com/Manual/UNetSpawning.html
But this “(and on the host)” breaks the whole “same code work on host, server and client” paradigm that uNet has. This property was probably rushed, because host should be considered as a client and server at the same time.
Anyway, did anybody came up with a good workaround ?
Never mind, I figured out what’s wrong. This is not an expected behavior (misunderstood manual text).
The thing is that I am not supposed to use hasAuthority immediately in Start() on host after spawning the object. Gotta use override-able NetworkBehaviour methods like OnStartAuthority for network-related initialization.
I’ve the same problem. I want spawn the player manually. After i run the scene with StartHost() or StartClient(), Unity tell me that the player object haven’t a local authority… How i can resolve this issue?