Developer Documentation

I get an UnityException when leaving PIE or loading a new scene.

UnityException: get_dataPath can only be called from the main thread.

Due to the asynchronous nature of leaving a room operation, the current recommendation is to avoid invoking this function within OnDestroy if the scene is being unloaded. Scene unloading could occur when transitioning between scenes or shutting down an application.

Instead, the best practice is to call the LeaveRoom function and subsequently wait for the OnRoomLeft event to be triggered. Once this event has been triggered, it is then safe to perform further actions, such as calling LoadScene or Application.Quit.

See also

Still need help?

Please check out support options like AI chatbot, Discord community and premium support packages.

Get in touch