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

Project Browser/Hierarchy

-

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

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.