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
- “Remove Unused Overrides” available on not loaded Scene and throws “ArgumentException: The scene is not loaded” warning
- Adaptive Probe Volume occlusion edge is calculated incorrectly when viewing probes near geometry edges
- Sampling a texture using an HLSL file throws shader errors and the code does not compile
- "Graphics.CopyTexture called with null source texture" error when Base Camera of an Overlay Camera is removed with DX11 Graphics API and Compatibility Mode enabled
- WebGL sends wrong value with large numbers when SendMessage function is used
Add comment