- Home /
Unity Photon, have player instantiated objects stay when player leaves
need some advice, working in unity using photon for a multiplayer, for those accustomed with photon there is a variable in the PhotonNetwork script which cleans up player network instantiated or created objects when the player leaves the room, which you can turn on or off by setting m_autoCleanUpPlayerObjects to true or false
the problem is the player can instantiate blocks which other players walk on and i want those to stay in game if the player leaves the game, so i thought setting autocleanup to false would fix this, but then the player and his camera stays in the game and messes everything up for the other players, thought about trying to delete it by setting it to destroy itself if the detected player id leaving the scene is identical but due the ownership is instantly transfered to the next player preventing it from deleting
Also i realise there is PhotonNetwork.InstantiateSceneObject whoch will instantiate objects to a scene, however only the master host can instantiate objects this way and all other players will not be able to
thoughts on how to fix? is there any way to stop the player objects from changing ownership, or maybe make the blocks you place change ownership to the next player to stop them deleting with autocleanup
How about just turning off the Camera and the player when he leaves ?
Answer by Akhil-Raja · Dec 03, 2015 at 11:58 AM
Instead of having player instantiated objects, you can have a function ( marked RPC) which instantiates the required gameobjects and then have a broadcast to everyone on the network. This will give you better control over those objects.
void instantiateFunction()
{
Instantiate(Prefab,gameobject.position,gameobject.rotation);
}
[RPC]
void Fire(PhotonMessageInfo info)
{
instantiateFunction();
}
void callRPC(PhotonTargets target)
{
photonView.RPC("Fire",target);
}
Your answer
Follow this Question
Related Questions
PhotonNetwork.InstantiateSceneObject works in editor but not in build 2 Answers
tracking ownership of shots 1 Answer
Photon Instantiate Prefab Script Problems 0 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