I am trying to make a player selection, where the player chooses his player from ui buttons and then spawns it. The script is working perfectly for the host player, but not for the connected clients.
[Command]
public void CmdSpawnCharacter() {
ClientScene.RegisterPrefab(PlayerPrefab);
var spawn = NetworkManager.singleton.GetStartPosition();
GameObject newPlayer = (GameObject)Instantiate(PlayerPrefab, spawn.position, spawn.rotation);
NetworkServer.Destroy(this.gameObject);
if (this.playerControllerId == 0)
{
NetworkServer.SpawnWithClientAuthority(newPlayer, this.connectionToClient);
}
if (this.playerControllerId > 0)
{
NetworkServer.SpawnWithClientAuthority(newPlayer, this.connectionToServer);
}
}
The object is being spawned on the client side, but as soon as it is spawned i get the error
" SpawnObject for RoguePlayer(Clone) (UnityEngine.GameObject), NetworkServer is not active. Cannot spawn objects without an active server.
UnityEngine.Networking.NetworkServer:Spawn(GameObject)
CharacterSelect:CmdSpawnCharacter() (at Assets/Scripts/CharacterSelect.cs:75)
UnityEngine.EventSystems.EventSystem:Update() "
I searched in a lot of places, and mostly all of them said to make the spawn function a [Command], but it is already a command and is still not working.