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! Your search result can be found below. Plus, we offer support via 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.

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

MomasVII
2022-10-04 06:12:19

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

Photon.Pun.PhotonNetwork:ConnectUsingSettings()

Com.Momas.NewRacer.NetworkManager:Connect()

Here is where I set the nickname of the player

PlayerNameInputField.txt

Uploaded 2022-10-04T06:12:16+00:00 1839 bytes

Comments

MomasVII
2022-10-08 05:22:10

Turn off Split Application Binary in Publishing Settings.

ronaldgevern
2023-06-07 07:45:21

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 = ...

}

else

{

// 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.

Back to top