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
- Mono Windows Builds don't produce full log callstacks when generating logs
- AssetBundles fail to load when running in Built Players for Mobile Devices
- UI elements with text gets bigger and grey when Player window is moved to another screen with different resolution
- System name accepts multiline text but crops it on confirmation, duplicates input, and shrinks the field when empty
- UI element scale and position are wrong in project build when DRS is changed with HDR and Software Dynamic Resolution enabled
Add comment