- Home /
How to manually destory GameObjects on player leaving game in Photon
To further explain there is a section in the PhotonNetwork script named autocleanup, by default this is set to true which means all objects owned by or instantiated by the player are destroyed when the player leaves the game, however i dont want all objects instantiated by the player to be destroyed so setting this to false prevents anything being destroyed, however now im having trouble trying to destroy the player character prefab upon a player leaving, i tried this
public void OnPhotonPlayerDisconnected(PhotonPlayer player) { if (player.ID == PhotonNetwork.player.ID) { Destroy (this.gameObject); } }
however it didnt work, i think because the object automatically changes owner when a player leaves, does anyone know a different method i can use to destroy the player?
Do you got a solution, I'm stuck on the same Problem :(
Answer by unity_R_FxE4AcMHOdHg · Oct 14, 2021 at 10:27 PM
I think the better way to do that is to establish control variables likes a boolean to make sure the order of application of the methods.
Your answer
![](https://koobas.hobune.stream/wayback/20220612052026im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Photon Network, how to spawn FPSController from Unity Standard Assets? 2 Answers
[Photon] Getting the players in a room in the same order 1 Answer
How to modify enemy players meshs with Photon Unity Networking? 1 Answer
Player names all displayed as local player photon 2 Answers
Photon player instantiation BY MAGIC!? 0 Answers