Player gameobjects deleted when performing large operations

I run into this issue when performing large performance heavy operations such as calculating pathfinding grids or performing large terrain operations at run time.

While performing an operation that takes 10-20 seconds to complete, I get lower FPS (which is expected), but when the operation completes, my game screen goes black. It looks like the game crashed, but I can see in the scene view, that the game is actually still running.

When I inspect the scene view, I see that my player character gameobject no longer exists which is why my screen went black. It actually looks like all dynamic objects got deleted, but all static objects are fine.

I am not locking the main thread, but I am definitely dropping my frame rate. I’ve run into this issue with a few different performance heavy operations, and the solution has always been to spread the load over a longer period of time.

Any idea why this is happening? I can’t predict when this will happen, so it will be very difficult to keep it from happening while playing the game.

Turns out Photon Unity Networking by default will delete your character when it detects that you’ve disconnected from the server.

I haven’t pinpointed why Photon thinks I’ve disconnected, but setting my Photon View Observer option to “Reliable Delta Compressed” seems to have solved the issue for now.