- Home /
Photon.Instantiate causes second-created player to swap places with first
Obviously working with PUN here. I'm creating a game based on the Marco Polo tutorial. I'm running one instance of the game on Computer 1 (my main machine), and I'm running another (build) instance on Computer 2 (the laptop sitting next to my main machine). (I'm running the other instance on a separate machine just to make sure that two instances on the same machine was not causing the problem I'm about to describe.)
I start one instance on Computer 1, go through the lobby, create the room, and join the room. My player prefab spawns at a random spot within a certain zone.
I start the second instance on Computer 2, join that game, and this new prefab should also spawn at a random place within the same zone, but instead, it immediately switches places with the spawned player on Computer. And the player on Computer 1 goes somewhere else (I assume where the Computer 2 prefab would have spawned, if it was working right).
The spawning code is pretty standard:
Vector3 spawnPosition = new Vector3(Random.Range(-10.0F, 10.0F), 0f, Random.Range(-10.0F, 10.0F));
PhotonNetwork.Instantiate(this.playerPrefab.name, spawnPosition, Quaternion.identity, 0);
Any thoughts why this might happen? Thanks.
Answer by Michael_-01-_ · Oct 26, 2015 at 12:34 PM
I am also working with PUN and one thing that you have to look out for is your player controlled scripts and camera's in the scene. I don't know if you have done this but make sure that your camera of your player prefab is disabled and then enable it with a script when you spawn the player, do the same for player controlled scripts, otherwise players would be able to control each other x_x Hope this helps :D
Good point. Now that I look closely at the behavior of the prefabs when I try to control them, I think you're right -- I need to make sure my camera scripts are really doing what they say they're doing. That might be the problem. Thanks.
I tried to fix this bug for a week. Thank you so mush!
Your answer
![](https://koobas.hobune.stream/wayback/20220612042736im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Photon Instantiate Prefab Script Problems 0 Answers
PhotonNetwork.InstantiateSceneObject works in editor but not in build 2 Answers
Photon Instantiate Group's, Instantiating Prefabs that should already Exist 1 Answer
Multiplayer game, object instantiated is being added for every single player 1 Answer