Hello,
I am trying to run a simple multiplayer scene of a hodt and a client walking around. As I have many other scripts accessing the player prefab it’s best for me to instantiate those on my own. I am using the following code for this, mostly taken from another post here:
[ServerRpc(RequireOwnership = false)]
public void SpawnPlayerServerRpc(ulong clientId)
{
Debug.Log("Spawning player with id: " + clientId);
GameObject newPlayer;
newPlayer = (GameObject)Instantiate(playerNetwork);
NetworkObject netObj = newPlayer.GetComponent<NetworkObject>();
newPlayer.SetActive(true);
netObj.SpawnAsPlayerObject(clientId, true);
}
This is where I call the method:
if (PlayerNetworkController.instance == null)
{
Debug.Log("Player does not exists.");
if (IsServer)
{
Debug.Log("Is server. Creating server player");
SpawnPlayerServerRpc(0);
} else {
Debug.Log("Is not server. Creating client player");
SpawnPlayerServerRpc(1);
}
} else {
Debug.Log("Player already exists.");
}
Why does this only ever create the host prefab? Everything apart from that works - the scene gets loaded for the client and you can even see the host prefab moving, but the client does not get its own prefab. It reaches the appropriate Debug.Logs, too, so there must be another issue.