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
- [UI Builder] Viewport's gizmos for Margin and Padding disappear when dragging to modify the value and the cursor leaves the Spacing section
- "Multiplayer Center" window does not reflect changes made in "Other Packages" section
- Crash on D3DKMTOpenResource when capturing with RenderDoc while GPU Skinning is set to GPU(Batched)
- Editing and saving Curve changes in UI Builder window throws multiple errors in the Console
- [UI Builder] Value is not selected when left clicking on Spacing/Border Widget values
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