Just wanted to check if this is the expected behaviour. Unity Version: 2021.1.0f1 / 2021.1.1f1
I made a custom EditorWindow and noticed that when opening my project in Unity, when my custom window is already open from the start, the execution order is always:
CreateGUI()
Awake()
OnEnable()
If you compare this to manually opening the custom window, the order is:
Awake()
OnEnable()
CreateGUI()
or after Reload Script Assemblies:
OnEnable()
CreateGUI()
So doing initialization stuff, that you need for building the UI, in OnEnable() or Awake() will cause problems when opening the project with your custom window already open, which is the reason I found this unexpected behaviour.
Going by their descriptions in the documentation, I thought Awake() and OnEnable() will always execute before CreateGUI(). Seems a little weird that the rootVisualElement of my window is ready( CreateGUI ) before my window is even open ( Awake ).
It also makes Awake() and OnEnable() not safe for initializing stuff and instead I have to put that into CreateGUI().
So my question is, if this behaviour is correct and if I should do all my initialization in CreateGUI() to make sure it always works?
Thanks