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

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.

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.

Help with a Unity crash potentially caused by PUN

2021-07-12 18:57:59

Hi! I've already posted this over at the Unity PUN forum, where I've attached crash logs as well. I don't think it's possible to attach logs here.

My game is running into a crash on scene/level load that I have identified to be caused potentially due to a change in how we are loading levels using Photon. The game on a pretty old version of PUN 2 - PUN 2.14, Photon lib:, so it does need to be upgraded.

Context for the issue: Earlier I was using PhotonNetwork.LoadLevel() with PhotonNetwork.AutomaticallySyncScene set to true. This was working fine, except for reloading levels (as is also mentioned in the documentation for this method in PUN 2 - reloading levels doesn't work on non-master clients). The level restart in my game works by actually reloading the scenes, so I changed the level loading system to use Raise Event instead. An event is raised from the master client, and then everybody does their own level loading once they receive the event.

My team noticed that this introduced an inconsistent crash during level loads in our game. More specifically, the crash seems to be happening when we try to use PhotonNetwork.InstantiateSceneObject() or PhotonNetwork.Instantiate(). In the PhotonNetwork.NetworkInstantiate() function overload that is called when an Instantiate event is received in the OnEvent() function, I added a simple log: "trying to instantiate ". While this isn't conclusive, it could help to see if all gameobjects that are supposed to be instantiated print those logs before the crash happens. On checking the crash log, I was only able to see ONE out of THREE such messages (the level spawns 3 different objects right after loading, but the crash seemed to have happened right after the spawn call for one of these objects). I'm attaching the crash dump, output log and error log for this crash.

I can't say with 100% certainty that the cause for this is the level load change, but that is one of the only few things that I changed about how levels are loaded in the game after which this crash started happening. I have made the following observations about this crash, however:

  • It is NOT a consistent crash, it seems to happen randomly.
  • If a level is constantly making Unity or the standalone build crash when trying to load the level, going offline and loading it once in offline mode will stop the crashes from happening for the rest of that session. This is why I think this issue could be related to something that I might have broken in the level load in online mode.
  • The crash seems to only happen on non-master clients.
  • The crash seems to happen more often on lower end devices.

The only difference that I could find in the level loading done via PhotonNetwork.LoadLevel vs the Raise Event loading is the lack of pausing of online messages queue. The new Raise Event loading doesn't set PhotonNetwork.IsMessageQueueRunning to false. Could this be potentially causing the said issue? I plan to add this in our custom loading anyway, so I wanted to confirm what would be the ideal places to pause and unpause the message queue. My understanding is that the IsMessageQueueRunning bool should be set to true when a level load message is received and we start loading a level, and then as soon as the level has finished loading, set this bool back to false.

Any help on this matter is greatly appreciated.


2021-07-13 08:58:00

I replied in the Unity forum:

Back to top