Search Issue Tracker
By Design
Votes
2
Found in
5.4.0b9
Issue ID
778391
Regression
Yes
DontDestroyOnLoad throws InvalidOperationException when called from the Editor
How to reproduce:
1. Open attached project
2. Open scene test.unity
- Note that an error appears in the console:
InvalidOperationException: The following game object is invoking the DontDestroyOnLoad method: BaseLoader. Notice that DontDestroyOnLoad can only be used in play mode and, as such, cannot be part of an editor script.
testScript.OnEnable () (at Assets/testScript.cs:11)
- Reproduced in Version 5.4.0b11 (323b0238353b), Version 5.4.0b7 (83df6fa5e23f), Version 5.3.4f1 (fdbb5133b820)
- Not reproducible in Version 5.4.0b6 (2c3d6b93e789), Version 5.2.4f1 (98095704e6fe)
- By Design: DontDestroyOnLoad was never intended to work in edit mode. Only in play mode and standalone players.
- This is why it now throws an exception if it is used in edit mode
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- [Android] Stage information is not logged when Log Shader Compilation is enabled
- [Vulkan] The memory allocation increases rapidly when there are multiple (three or more) Real-Time Reflection Probes in the Scene
- [macOS] Library folder of the opened project can be deleted which leads to the crash
- “Default Scene” dropdown field contains a spelling mistake “Default Builtin”
- Editor crashes on PPtr<Mesh> after adding Text Mesh and Cloth Components to the same GameObject
Add comment