Issue with spawning/destroying pooled objects from clients

ChristianWiele

Active member
Hi,

I would like my characters to spawn objects that they own and control using the object pool, but ran into 2 issues:

1.) Any client can instantiate pool objects. I use the NetworkSpawn method and set the sceneObject to false. Initially, the owner is set correctly, but if the object is reused by another client the owner is not changed to the new owner.
2.) The objects can be spawned by any client, but can only be destroyed by the master client.

I can fix the first issue by explicitly transferring ownership, but I don't know how to deal with the second one.

Regards, Christian
 
I both of these cases there isn't anything built in to the add-on so it'll require your own solution. Transferring ownership for number 1 sounds right, and maybe for number 2 you could add a new component which specifies that only the master client can destroy the object? Or an interface?
 
There might be a misunderstanding for #2. The issue is that you have a master client check in the destroy method of the PunObjectPool. But instantiating can be done from any client. I don't see an obvious reason for this check in the destroy method. So would it be an option for you to remove it? For the time being I raise the event in my own code to destroy objects from non-master clients.

/// <summary> /// Internal method which destroys the object instance on the network. /// </summary> /// <param name="obj">The object to destroy.</param> protected override void DestroyInternal(GameObject obj) { m_ActiveGameObjects.Remove(obj); ObjectPool.Destroy(obj); if (PhotonNetwork.IsMasterClient) { var photonView = obj.GetCachedComponent<PhotonView>(); if (photonView != null) { PhotonNetwork.RaiseEvent(PhotonEventIDs.ObjectDestruction, photonView.ViewID, m_RaisedEventOptions, m_ReliableSendOptions); } } }
 
All of the objects are spawned on the server and transmitted to the clients so that's why they should be removed on the server. The server will then call the description code on all of the clients.
 
Top