Object reference not set to an instance of an object error.

Can someone help me debug this issue. It will work in editor but not on my mobile build.

Any advice where to start. Seemed to happen all of a sudden.

It seems to crash at every point "PhotonNetwork." is called. It might not be able to find the settings in the Resource folder maybe? Even though it exists.

NullReferenceException: Object reference not set to an instance of an object.

at Photon.Pun.PhotonNetwork.set_NickName (System.String value) [0x00000] in <00000000000000000000000000000000>:0 

NullReferenceException: Object reference not set to an instance of an object.

 at Photon.Pun.PhotonNetwork.StaticReset () [0x00000] in <00000000000000000000000000000000>:0 

 at Photon.Pun.PhotonNetwork..cctor () [0x00000] in <00000000000000000000000000000000>:0 

 at Com.Momas.NewRacer.NetworkManager.Awake () [0x00000] in <00000000000000000000000000000000>:0 

Rethrow as TypeInitializationException: The type initializer for 'Photon.Pun.PhotonNetwork' threw an exception.

 at Com.Momas.NewRacer.NetworkManager.Awake () [0x00000] in <00000000000000000000000000000000>:0 

Autoconnected Player Can't connect: Loading settings failed. ServerSettings asset must be in any 'Resources' folder as: PhotonServerSettings



Here is where I set the nickname of the player


  • Turn off Split Application Binary in Publishing Settings.

  • ronaldgevern
    edited June 2023

    An object is an instance of a class, and it resides in memory at a specific location. A reference is a pointer that describes the memory location where the object is stored. When you encounter the message "object reference not set to an instance of an object," it means that you are trying to access an object that either doesn't exist, has been deleted, or has been cleaned up.


    if (mClass != null)


    // Go ahead and use mClass

    mClass.property = ...




    // Attempting to use mClass here will result in NullReferenceException


     To avoid encountering a NullReferenceException, it is generally preferable to prevent the error from occurring in the first place. This can be done by testing objects for null before using them. By checking if an object is null before performing operations on it, you can handle potential null references gracefully and take appropriate actions to prevent errors or unexpected behavior.