Stop certain objects being destroyed when player leaves
Options
Hi all
Just wondering if there is a way to stop objects being destroyed when players leave a room. I have build a system that can turn objects into network aware views at runtime and everything hooks up and moves/preforms correctly. I dont want these components to be destroyed when the person who make something network aware leaves the room.
I looked into using PhotonNetwork.autoCleanUpPlayerObjects = false however this then does not destroy anything (i still want their avartar to be destroyed just not their objects)
Because i am creating some of the views at runtime i can not sure the PhotonNetwork.InstantiateSceneObject() because the object already exists.
currently my solution is to when i create the objects through RPC's to assign an instantiationId and then manually clean up game objects using but this does not seem to work either as when a player then reconnects it creates the player that has left on the network.
Thanks
Just wondering if there is a way to stop objects being destroyed when players leave a room. I have build a system that can turn objects into network aware views at runtime and everything hooks up and moves/preforms correctly. I dont want these components to be destroyed when the person who make something network aware leaves the room.
I looked into using PhotonNetwork.autoCleanUpPlayerObjects = false however this then does not destroy anything (i still want their avartar to be destroyed just not their objects)
Because i am creating some of the views at runtime i can not sure the PhotonNetwork.InstantiateSceneObject() because the object already exists.
currently my solution is to when i create the objects through RPC's to assign an instantiationId and then manually clean up game objects using but this does not seem to work either as when a player then reconnects it creates the player that has left on the network.
public void OnPhotonPlayerDisconnected(PhotonPlayer player) { if (PhotonNetwork.player.IsMasterClient) { if (GetComponent<PhotonView>().instantiationId == player.ID) { PhotonNetwork.Destroy(gameObject); } } }wondering if there is a way i can mark a created network view to be controlled by the scene or make it so its not tied to the player that created the view.
Thanks
0
Comments
-
Ok so have now gotten somewhere else. I can checking when a player disconnects and dpoong the following:
if (PhotonNetwork.isMasterClient) //destroy all objects that need to be removed when the player leaves
{
List playerViews = new List();
foreach (PhotonView view in PhotonNetwork.networkingPeer.photonViewList.Values)
{
if (view !=null && view.CreatorActorNr == player.ID && !view.GetComponent().PresistAfterPlayer)
{
playerViews.Add(view);
}
}
foreach (PhotonView t in playerViews)
{
Debug.Log("Destroy : " + t.gameObject.name);
PhotonNetwork.RemoveRPCs(t);
PhotonNetwork.Destroy(t.gameObject);
}
}
this appears to be working and cleaning up the objects and not getting them to respawn when a new player connects. However i an now getting the following error whenever a new player connects after a previous player leaves "Ev Destroy Failed. Could not find PhotonView with instantiationId 1. Sent by actorNr: 0" with different instantiationId for each player number.
im guessing although i am removing RPC's the destroy is then added one back in or something but not 100% sure if this is the reason or not.
Thanks for any help1