PhotonNetwork and PunObjectPool error

EpMan

New member
Hello everyone, I have a problem with destroy an object via PhotonNetwork (PunObjectPool error).
I spawn object with
PhotonNetwork.Instantiate(prefabGO.name, DropPoint.transform.position, DropPoint.transform.rotation); // just for example
and destroying it with
PhotonNetwork.Destroy(this.gameObject); // in script of that object
I getting error:
NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateCharacterController.AddOns.Multiplayer.PhotonPun.Game.PunObjectPool.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Opsive/UltimateCharacterController/Add-Ons/Multiplayer/PhotonPUN/Scripts/Game/PunObjectPool.cs:216)

Photon.Realtime.LoadBalancingClient.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3142)
ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer stream) (at <a497a6f18e1f4b419421b940add27a6e>:0)
ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands () (at <a497a6f18e1f4b419421b940add27a6e>:0)
ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () (at <a497a6f18e1f4b419421b940add27a6e>:0)
Photon.Pun.PhotonHandler.Dispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:208)
Photon.Pun.PhotonHandler.FixedUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:142)
I already tried to fix this by checking for if(photonView.gameObject != null) (in PunObjectPool.cs:216) , but the problem is not fixed.
If I do not have to spawn objects via PhotonNetwork or destroy through it, please tell me how to do this so that everyone has an object and does not have this error after destroying.

The object is deleted and everything about the object's script works fine, but only this error occurs. If it is possible to bypass the call of this event, please also inform about the possibility and how to do it.

Thanks for your attention. Any help would be appreciated.

EDIT: After testing, it turned out that this problem occurs for players who are not master clients. We master all customers without error.
Moreover, regardless of who is the owner of the thing and who (the owner) deletes it.
 
Last edited:
It looks like I found a solution to the problem. I spent more time debugging in VS and and realized that checking photonView != null and photonView.gameObject != null are not equivalent.
Before:
} else if (photonEvent.Code == PhotonEventIDs.ObjectDestruction) {
var photonView = PhotonNetwork.GetPhotonView((int)photonEvent.CustomData);
// The object may have already been pooled by the time it was received over the network.
if (ObjectPool.InstantiatedWithPool(photonView.gameObject))
{
DestroyInternal(photonView.gameObject);
}
}
After:
} else if (photonEvent.Code == PhotonEventIDs.ObjectDestruction) {
var photonView = PhotonNetwork.GetPhotonView((int)photonEvent.CustomData);
// The object may have already been pooled by the time it was received over the network.
if (photonView != null)
{
if (ObjectPool.InstantiatedWithPool(photonView.gameObject))
{
DestroyInternal(photonView.gameObject);
}
}
}
The error no longer appears, but does this check have any detrimental effect on other UCC functions?
Shouldn't, but still the question is open.

When should I use PunObjectPool and where can I find examples of use?
 
Top