Quantcast
Channel: Photon Unity Networking (PUN) — Photon Engine
Viewing all articles
Browse latest Browse all 8947

NullReferenceException at MonoBehaviourPun.get_photonView

$
0
0
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:
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?

Viewing all articles
Browse latest Browse all 8947


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>