Problem Cleaning up Prefab with multiple PhotonViews

Hey all,

I have a prefab which has a PhotonView Component so that I can Photon Instantiate it at run time. One of its child objects also has a photon view component which I use for observation of elements specific to that sub object. Problem is, at the end of a match, when I'm running my cleanup code, and call PhotonNetwork.Destroy on the base object I get errors thrown from the child object.

I'm thinking one way around this is to remove the child object (Lets call them Gun Barrels) from the prefab (Lets call them Turrets), then have Turrets instantiate Gun Barrels, and then parent the Gun Barrels to the Turret. Then during cleanup, specifically search for Gun Barrels and Photon destroy them before going on to Photon destroy Turrets. This seems like it would work, but it also feels a bit messy.

Are there some magic words I can throw at an object with multiple views distributed through its children, or is it going to be the more involved method mentioned above?

Thank you for your help everyone.


  • Tobias
    I could use a simple repro case to investigate and find a fix. So far, I didn't have issues with destroying multiple PVs but maybe I didn't test a similar scenario either.

    From what I read, the setup sounds a bit more complex than how I would approach it. I tend to aggregate parts of an entity into it's parent, unless it gets too messy. This means: I think I would use a PV per Turret, then add a script that controls the sub-components. This could implement OnPhotonSerializeView and send only the updates really needed per interval. RPCs would always target the Turret but you can easily assign a number per barrel to make it move or act. If that's important to show individually correct. If the Turret should just shoot (and it doesn't really matter which Barrel was fired), then you could actually send a "shoot" RPC and make each client pick the next barrel in the queue (using one after the other). This saves a few bytes traffic, which in turn might improve network lag or stability.
  • Memige
    Thanks for the feedback Tobias,

    I tend to agree with the over-complexity angle. I'll try some minor restructuring and see if I can't get something a little more elegant then sub-instantiating. I'll let everyone know how it goes.

    Best Regards,