So I am not sure what I did but I had this working at one point now it doesn’t.
To give an overview of what is going on when a player clicks the join the game it will spawn a prefab owned by that connected user.
Here is the code that is called when clicking to join the game:
if(networkView.isMine){
if(PersistantObject.readyplayers == PersistantObject.connectedplayers ){
if(GUI.Button(new Rect(230,200, 150, 50), "Join Game")){
if(do_once){
inLobby = false;
networkView.RPC("IncJoinedPlayers", RPCMode.AllBuffered);
SpawnPlayer();
do_once = false;
}//end do_once
}//end button
}//end readyplayers = connected player
}//end networkview.ismine
Now here is the code for the “SpawnPlayer()” function that is called:
private void SpawnPlayer()
{
if(networkView.isMine){
inLobby = false;
if (PersistantObject.ImAGhost) {
Network.Instantiate(prefab_ghost, GhostLocation.transform.position, Quaternion.identity, 0);
}else{
if(chr_number == 1){
Network.Instantiate(playerPrefab_ethan, spawnLocation.position, Quaternion.identity, 0);
}else if(chr_number == 2){
Network.Instantiate(playerPrefab_robot, spawnLocation.position, Quaternion.identity, 0);
}else if(chr_number == 3){
Network.Instantiate(playerPrefab_goblin, spawnLocation.position, Quaternion.identity, 0);
}
//chr_number = 0;
networkView.RPC ("IncListCount", RPCMode.AllBuffered);
}
}
}
The “chr_number” is the chosen character in prior menu screens.
So it works if I test it by myself but if I test a server and client then it crashes unity and freezes the other that I am testing as soon as I click “Join Game” button.
Any help on this would be amazing. I found some similar issues with network.instantiate on other forums but nothing that can fully answer my question.
Here is a picture of the button that is pressed, its an OnGUI() call: