Probably the most often error from my crash logs is caused by a null reference exception coming from PUN2. When I try to access photonView I'm getting an NRE coming from the code I don't control:
The code of my update method is pretty simple, I'm just checking if that's my photon view to control before executing custom logic:
I do kill the and instantiate myOtherCoolController instances in runtime so it's some kind of race condition which is hard to reproduce but my players can reproduce it fairly often and lots of them are affected (hundreds). What is the tight way to reliably access photonView?
NullReferenceException: Object reference not set to an instance of an object.
Managed Stack Trace:
Photon.Pun.PhotonView.Get (UnityEngine.Component component) (at <00000000000000000000000000000000>:0)
Photon.Pun.MonoBehaviourPun.get_photonView () (at <00000000000000000000000000000000>:0)
MyCoolController.Update () (at <00000000000000000000000000000000>:0)
The code of my update method is pretty simple, I'm just checking if that's my photon view to control before executing custom logic:
public MyOtherCoolController myOtherCoolController; public void Update() { if (!myOtherCoolController.photonView.IsMine) return; // ... do stuff }
I do kill the and instantiate myOtherCoolController instances in runtime so it's some kind of race condition which is hard to reproduce but my players can reproduce it fairly often and lots of them are affected (hundreds). What is the tight way to reliably access photonView?