Why am I getting a null?

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Why am I getting a null?

playerDotName
2021-12-02 00:20:35

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?

Comments

Tobias
2021-12-02 16:00:52

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.

Back to top