I’ve encountered what appears to be unexpected behavior in Unity when working with Addressables to load scenes asynchronously.
Steps to reproduce:
- Create a project with Addressables package
- Create a test scene (e.g., “example.unity”) with some GameObjects containing MonoBehaviours
- Add the scene to Addressables
- In your main scene, load the test scene asynchronously with activateOnLoad = false:
var handle = Addressables.LoadSceneAsync("example.unity", LoadSceneMode.Additive, false);
var sceneInstance = await handle.Task;
- Stop Play mode in the Unity Editor before calling sceneInstance.ActivateAsync()
Expected behavior:
Since the scene was loaded with activateOnLoad = false and was never activated before stopping Play mode, the Awake() methods of MonoBehaviours in that scene should not be called.
Actual behavior:
The Awake() methods of MonoBehaviours in the loaded but not activated scene are being called during editor Play mode shutdown.
Additional observations:
-
The Application.quitting and Application.unloading events are not triggered at the time these unexpected Awake() calls happen
-
This creates a situation where I cannot properly handle exceptions or prepare for this early initialization
-
The behavior is problematic because objects may try to access dependencies or systems that are already being torn down as part of the Play mode exit process
Unity version:
60000.0.41
Question:
Is this the intended behavior? If so, how should developers handle this situation to prevent errors when MonoBehaviours in non-activated scenes attempt to initialize during Play mode shutdown?
As a result, this situation can cause crashes when stopping Play mode in the editor.
Additionally, in this situation, the Awake calls occur before both Application.quitting and Application.unloading events are triggered.