Why am I getting a null reference exception error?
Options
Taran
✭
When I play my scene I receive this error (at this point I haven't connected/attempted a connection to Photon) -
NullReferenceException : Object not set to an instance of an object. Photon.Pun.PhotonNetwork.AddCallbackTarget (System.Object target) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:85)
This error is stopping me from connecting to photon. Anyone know how I can fix this?
NullReferenceException : Object not set to an instance of an object. Photon.Pun.PhotonNetwork.AddCallbackTarget (System.Object target) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:85)
This error is stopping me from connecting to photon. Anyone know how I can fix this?
0
Answers
-
Hi @JohnTube,
I am using PUN2. Regarding the error, I have noticed that it occurs every other time I play the scene. So I can play the scene and the error doesn't appear and I can connect to photon and everything seem to be working fine. Then the next time I play the scene the error appears and I cannot connect. This process seem to repeat itself infinitely. The code/error for the AddCallbackTarget isn't in any of my created scripts but is coming from PhotonNetworkPart (script which has come with Photon). Here is the code snippet from that script:
public static void AddCallbackTarget(object target)
{
if (target is PhotonView)
{
return;
}
IPunOwnershipCallbacks punOwnershipCallback = target as IPunOwnershipCallbacks;
if (punOwnershipCallback != null)
{
OnOwnershipRequestEv += punOwnershipCallback.OnOwnershipRequest;
OnOwnershipTransferedEv += punOwnershipCallback.OnOwnershipTransfered;
}
NetworkingClient.AddCallbackTarget(target);
}
Believe this is the full stack trace of the error:
NullReferenceException: Object reference not set to an instance of an object
Photon.Pun.PhotonNetwork.AddCallbackTarget (System.Object target) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:85)
Photon.Pun.MonoBehaviourPunCallbacks.OnEnable () (at Assets/Photon/PhotonUnityNetworking/Code/PunClasses.cs:225)
What do you mean by the minimal repro steps?0 -
Okay. The class I have which extends MonoBehaviorPunCallbacks doesn't call the awake method (and neither does any other class within my scene) so that's a bit strange. I am going to move my script into a new clean project will only PUN2 downloaded and see whether or not the issue still persists.1
-
I see the issue now.
First time we get such report.
PhotonNework.NetworkingClient is still null when PhotonNetwork.AddCallbackTarget is called which is not expected as the NetworkingClient is set in the constructor when the singleton instance is first created.
We will investigate.
Thanks for your report and patience!0 -
Hi! I've started to have same issue after I've switched to Compute Engine VM (not sure is that related)NullReferenceException: Object reference not set to an instance of an object
Photon.Pun.PhotonNetwork.AddCallbackTarget (System.Object target) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:85)
Photon.Pun.MonoBehaviourPunCallbacks.OnEnable () (at Assets/Photon/PhotonUnityNetworking/Code/PunClasses.cs:225)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
I've also updated Pun2 asset to the latest version. My class extending MonoBehaviourPunCallbacks and here the Start methodvoid Start() { if (!PhotonNetwork.IsConnected) { PhotonNetwork.AutomaticallySyncScene = true; PhotonNetwork.GameVersion = gameVersion; PhotonNetwork.ConnectUsingSettings(); } Debug.Log(PhotonNetwork.LocalPlayer.UserId + " pid in start"); progressLabel.SetActive(false); //controlPanel.SetActive(true); }
0 -
In additional to that I have this error as wellNullReferenceException: Object reference not set to an instance of an object
Photon.Pun.PhotonNetwork.set_GameVersion (System.String value) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetwork.cs:87)
Launcher.Start () (at Assets/Scripts/Launcher.cs:98)
where Launcher.cs:98 isPhotonNetwork.GameVersion = gameVersion;
from start method0 -
Hi @JohnTube,
I am using PUN2. Regarding the error, I have noticed that it occurs every other time I play the scene. So I can play the scene and the error doesn't appear and I can connect to photon and everything seem to be working fine. Then the next time I play the scene the error appears and I cannot connect. This process seem to repeat itself infinitely. The code/error for the AddCallbackTarget isn't in any of my created scripts but is coming from PhotonNetworkPart (script which has come with Photon). Here is the code snippet from that script:
public static void AddCallbackTarget(object target)
{
if (target is PhotonView)
{
return;
}
IPunOwnershipCallbacks punOwnershipCallback = target as IPunOwnershipCallbacks;
if (punOwnershipCallback != null)
{
OnOwnershipRequestEv += punOwnershipCallback.OnOwnershipRequest;
OnOwnershipTransferedEv += punOwnershipCallback.OnOwnershipTransfered;
}
NetworkingClient.AddCallbackTarget(target);
}
Believe this is the full stack trace of the error:
NullReferenceException: Object reference not set to an instance of an object
Photon.Pun.PhotonNetwork.AddCallbackTarget (System.Object target) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:85)
Photon.Pun.MonoBehaviourPunCallbacks.OnEnable () (at Assets/Photon/PhotonUnityNetworking/Code/PunClasses.cs:225)
What do you mean by the minimal repro steps?
This has just happened to me as well - updated to the latest version of PUN2 and every other time I hit play I get the same null reference exception. Occurred on both 2019.3.3f1 and 2019.3.12.f1.
I rolled back to the old package and the issue immediately went away. I have a very basic setup integrating PlayFab authentication (pretty much just followed the tutorials).
I will stay on the old version for now but thought you may be interested to know it is still occurring.
Cheers.0 -
Did you disable "Domain Reloading" maybe?
https://docs.unity3d.com/Manual/DomainReloading.html1 -
-
Did you disable "Domain Reloading" maybe?
https://docs.unity3d.com/Manual/DomainReloading.html
Thank god for this post - Domain Reloading was exactly the problem for me. Was so confused why everytime I created a new project the issue wouldn't exist.. but in my real project it would break.. it was because I disabled Domain Reloading!0