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

Physics

-

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

  1. 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

  2. Resolution Note (fix version 2020.3):

    Fixed in Unity 2020.3.2f1

Comments (1)

  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

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.