It’s not different in Unity C#. The MonoBehaviour does not declare the Awake() (or Update, Reset, etc) method, so there’s nothing to override.
Unity instead checks your derived class for any of this methods via reflection (I assume) and calls it if available.
mmhh… If I look Monobehavior documentation I find a section called “OVERRIDABLE FUNCTIONS”. In this section is also Awake listed. I think it is declared in Monobehavior and there is something to override. And if there is something to override you have to mark it as override in “normal C#”. So Unity C# is different.
Thats my understanding of it. Maybe I am wrong.
Like mentioned in Jessy’s link (thank you) its because unity is using reflections to call these methods? But why voilating the standard and is reflection not slower then a normal function call?
It only calls the functions if you implement them, which can lead to performance improvements over always calling every function on every component.
It might still be clearer if MonoBehaviour did provide a prototype for the functions, and it would help you to know you’d spelled the function name correctly (OnGUI vs OnGui?) and also act as in-editor documentation for what you can override, but the call is not made through the base class, so it’s not necessary for it to provide the methods in order to function.
Using the MonoDevelops assembly browser you can verify that the MonoBehaviour does not declare those functions:
public class MonoBehaviour : Behaviour
{
// Constructors
public MonoBehaviour ();
// Methods
public void Invoke (string methodName, float time);
public void InvokeRepeating (string methodName, float time, float repeatRate);
public void CancelInvoke ();
public void CancelInvoke (string methodName);
public bool IsInvoking (string methodName);
public bool IsInvoking ();
public Coroutine StartCoroutine (IEnumerator routine);
public Coroutine StartCoroutine_Auto (IEnumerator routine);
public Coroutine StartCoroutine (string methodName, object value);
public Coroutine StartCoroutine (string methodName);
public void StopCoroutine (string methodName);
public void StopAllCoroutines ();
public static void print (object message);
// Properties
public bool useGUILayout { get; set; }
}
The section called “OVERRIDABLE FUNCTIONS” is just a title in the documentation that says you can implement these to do Unity specific stuff, it does not relate to any overridable virtual C# functions.