NullReferenceException when joining room from PhotonNetworkPart

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:3356)
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:565)
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)

I am not sure what is going on here. I searched for a fix to this but as far as i know this was fixed back in 2019 yet I am having an issue when trying to update ownership. The only issue is that I do not think I am truing to update any ownership at any point.

Steps:
I create a room and join with on player.
I attempt to join the same room with a 2nd player and I get the NullReferenceException.

This is my create room call
RoomOptions roomOpts = new RoomOptions(){IsVisible = true, IsOpen = true, MaxPlayers = (byte)_roomSize};
PhotonNetwork.CreateRoom(_roomName, roomOpts);

This is my join room call
PhotonNetwork.JoinRoom(roomName);

Any help would be great.. if you need more information I will do what I can to get it for you.

Thank you

Comments

  • Hi @Overrated,

    Thank you for choosing Photon!

    What PUN version is this?
    Do you change ownership explicitly?
    Do you change default ownership mode?
  • This could be due to the Master Client knowing views that this player doesn't know yet.
    Do you use PUN's built in scene synchronization? Or do you at least pause dispatching incoming messages while you load the scene?
    Refer to Switching Scenes.
  • Tobias thank you very much. This was indeed the issue and setting PhotonNetwork.AutomaticallySyncScene = true fixed the issue.