Why am I getting a null?

Options
NullReferenceException: Object reference not set to an instance of an object
Photon.Pun.PhotonNetwork.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:2415)
Photon.Realtime.LoadBalancingClient.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3342)
ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (ExitGames.Client.Photon.StreamBuffer stream) (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/PeerBase.cs:898)
ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands () (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/EnetPeer.cs:563)
ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands () (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/PhotonPeer.cs:1863)
Photon.Pun.PhotonHandler.Dispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:221)
Photon.Pun.PhotonHandler.FixedUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:147)

---

When my players join, I spawn characters for each of them. Occasionally, one instance of the game will not have a camera because no character has spawned. The instance this happens to registers the above error. I have no idea why that's happening and no idea how to begin to troubleshoot it.

Does anyone recognize this?

Answers

  • Tobias
    Options

    I think this is a part of code that we updated recently in PUN 2. If for some reason, the viewId could not be found, there is no view. So .. this will be null.

    The cause for that, in turn, is likely you either failed to instantiate it or the game logic used a UnityEngine.Destroy() on a networked object. You want to debug if the object in question existed and if it did, why it doesn't anymore.

    You could add logging to PUN or the objects to log when they get created and destroyed and which photonView.viewId they had.

    When this happens, log the viewId in question and check your log and you might realize what's up.

    Note: Loading scenes will also destroy GOs.