In Unity/UNet:
How do you correctly spawn a NetworkPlayer
? Proper now, I am doing it like this from inside a NetworkManager
derived class:
public override void OnServerAddPlayer(NetworkConnection conn, brief playerControllerId) {
NetworkPlayer newPlayer = Instantiate<NetworkPlayer>(m_NetworkPlayerPrefab);
DontDestroyOnLoad(newPlayer);
NetworkServer.AddPlayerForConnection(conn, newPlayer.gameObject, playerControllerId);
}
This code snippet works fairly properly and each shoppers can talk with one another. Nevertheless, there are just a few little points that come up solely on the host:
- In Unity’s hierarchy-view on the host, there are solely two
NetworkPlayer
cases. Should not there be 4 NetworkPlayer cases on the host? Two shopper cases and two server cases? If that’s the case, do you’ve any concepts what might trigger the lackingNetworkPlayer
cases? - The 2 NetworkPlayer cases have each, their
isClient
andisServer
flags set totrue
. However solely one of many has it isisLocalPlayer
flag set. Now I’m wondering if this habits is as meant? And if that’s the case, how do you distinguish between the shopper and the server occasion of aNetworkPlayer
? - Two participant habits: If the distant shopper sends a
[Command]
that modifications a[SyncVar]
on the server, then on the host, the[SyncVar]-hook
is named solely on theNetworkPlayer
occasion that represents the distantNetworkPlayer
. The[SyncVar]-hook
is just not referred to as on the host’s"isLocalPlayer-NetworkPlayer"
occasion. Should not the[SyncVar]-hook
be referred to as on eachNetworkPlayer
cases?
Any advise is welcome. Thanks!