Question by
Epsilone · Sep 02, 2021 at 01:15 PM ·
uitextinheritanceoverrideorder-of-execution
Inheriting text class messed up Execution Order
Long story short, I was creating a personal Text class by inheriting the unity one, when a bunch of strange behavior of my script lead me to this discovery: the order of events like Start, OnEnable, OnDestroy etc was completely messed up.
I've simplified the class to its minimum :
using UnityEngine.UI;
public class MyText : Text
{
protected override void Awake() => print("Awake ");
protected override void Start() => print("Start");
protected override void OnEnable() => print("OnEnable");
protected override void OnDestroy() => print("OnDestroy ");
}
}
Here is the result of executing a scene with this component on a gameobject:
1) When we enter play mode, it will log:
OnEnable
OnDestroy
Awake
Start
2) When we stop the play mode, it will log:
OnDestroy
Awake
OnEnable
Start
Also I tried every combination of "virtual" "new" "private" "base.method(); that I could think of but it didn't change the result at all.
Seriously I have no idea what is happening here, does someone have an idea? Why our classic unity methods are not behaving correctly?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613042510im_/https://answers.unity.com/themes/thub/images/avi.jpg)