Search Issue Tracker
Fixed in 2021.2.X
Fixed in 2020.3.X, 2021.1.X
Duplicate in 2021.1.X
Votes
0
Found in
2017.4
2019.3.9f1
2020.2
Issue ID
1239147
Regression
No
OnEnable/OnDisable is called the second time when setting GameObject's instance flags to HideAndDontSave
How to reproduce:
1. Open the attached project's Scene labeled "MyScene"
2. In the Hierarchy, select the "GameObject"
3. In the Inspector, Right-Click the "Hide And Dont Save Object" Component
4. From the context menu, select the "CreateInstanceWithHideFlags" option
5. Observe the Console Window
Expected result: OnEnable/OnDisable functions are called once
Actual result: OnEnable/OnDisable functions are called multiple times
Note: The extra deactivation and activation comes from UnityScene::HandleChangingPhysicsScenes
Reproducible with: 2017.4.40f1, 2018.4.22f1, 2019.3.11f1, 2020.1.0b6, 2020.2.0a8
Comments (1)
-
_watcher_
May 05, 2020 08:15
OnEnable/OnDisable triggering multiple times has been an issue in the Editor for many years. I had to stop using these completely and implement my own solution, unfortunately. Still would be awesome if they worked properly.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Crash on GUIManager::DoGUIEvent when focusing on the Game view window on a specific project
- Asset creation in the Project Browser is not always undone/inconsistent when the undo shortcut is pressed right after creating an asset
- JobTempAlloc memory leak warning is thrown when the Player is shut down
- Graphics State Collection warm-up does not work when using with Addressables Shaders
- "Baked Shadow Radius" field is visible but inactive when when the Shadow Type is set to "Hard Shadows" under the Light Component
Resolution Note (fix version 2021.2):
Setting certain hide flags internally removes the object from the scene into a separate hidden scene. The deactivation/reactivation of objects needs to happen to ensure the object does not reach a point where it belongs to one scene, but is affected by the physics of another scene. The extra round of activations can be worked around by deactivating the gameObject first, setting the hideFlags and Activating the object again.
Fixed in 2021.2.0a5
Resolution Note (fix version 2020.3):
Fixed in Unity 2020.3.2f1