- Home /
The question is answered, right answer was accepted
Network.Instantiate crashes my game
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:
Answer by wesleywh · Oct 22, 2014 at 11:42 PM
Well I may have just solved my problem! I feel dumb for not checking this before but hopefully this will help someone else out that is having the same problem that I was. The first thing that I did was I turned off my firewall. Now this is good for testing just make sure not to leave it off ;). Then I changed one line of code that was listed above. In OnGUI() script, not the SpawnPlayer() script, I removed the line if(Network.isMine). After doing those two things everything started working again. Summery: Turn off your firewall Check to make sure you're using Network.isMine in the correct location
Follow this Question
Related Questions
Network.Instantiate a Non-prefab 1 Answer
Weird network spawning bug. 1 Answer
Network rigidbody synchronize 0 Answers
SpawnWithCLientAuthority Issues... 0 Answers
how i can apply changes objects on Network.Instantiate? 1 Answer