Clean up Instantiate event for a player when CleanupCacheOnLeave = false

Options
Hi

Having a problem with PUN currently and can not get to the bottom of it. I am creating rooms with the CleanupCacheOnLeave set to false and manually destroying objects when needed. This is because i need to have objects persist when the player who made them leaves the room.

When a player leaves i am going though all of their player views and removing the RPCs that are associated with them for the objects i need to clean up, events etc but then leaving the ones for objects i need to stay spawned (placeable blocks etc).

The problem im having is when im spawning the player with PhotonNetwork.Instantiate() when the player leaves and a new player joins it is still fireing this event and creating an empty player object in the room thats not hooked to anything. Currently getting round this with an OnPhotonInstantiate() turning the game object off if the info.sender == null. But there must be a better way round this as this feels very hacky.

I have also tried the photon.Destroyplayerobjects after transfering all objects ownership to other players but then this destorys the ones they created before they left.

Any ideas?

Comments

  • Looking into the event cache info some more, it looks like i need to do something similar to this:
    Use case 2: If you use a Hashtable as event content, you can mark all events belonging to some object with an "oid" key (short form of "ObjectID") and some value. When you want to clean up the cache related to a specific object, you can just send a Hashtable(){"oid", } as event data filter and EventCaching.RemoveFromRoomCache.

    and then do a removefromroomcache with the object id passed into it, but how do i get the oid of the hash table or am i reading that wrong?
  • Ok fixed it :)

    Looks like my InstantiationId was being set to something different to what it should be, but now i have fixed that looks like PhotonNetwork.Destroy() works fine to clean up the instination event :)