I’m experiencing some undocumented functionality trying to extend a UnityEngine.UI.Text - it seems that the event order is not as documented (Awake → OnEnable → Start) but instead occurs as (OnDisable → OnEnable → Awake → Start). I’ve tested it, and it happens all the way back down the chain to UnityEngine.UI.Graphic.
I’m trying to use OnEnable / OnDisable to register / deregister event handlers for the component.
Script execution order does’t solve this, as even though it’s set as lower priority and Awake gets called after default time, the OnDisable → OnEnable seems to happen independently from the expected event order.
Has anyone had an issue like this / able to suggest a workaround?
This behavior only occurs in the editor. What you’re seeing is some behind the scenes housekeeping as the editor cleans up the scene for transition to play mode. Awake is the first thing that occurs once the scene has entered play mode. You can verify this with the following:
And to clarify the workaround: Wrap your important stuff within if Application.isPlaying blocks to ensure that no changes occur inside the editor during this time.