How come start and update methods aren't virtual?

Hello everyone,

I was just wondering why (and how) Unity allows me to do the following in C#:

public void Start()
{
    // Do something here
}

public void Update()
{
    // Do something here
}

Do the Start and Update methods inherit from MonoBehaviour? Why is it that I don’t have to override a virtual method to use Start and Update? Are they virtual methods?

Anyone that can shed some light on this will be praised and loved :slight_smile:

Thanks

MonoBehaviour doesn’t define the methods at all - they’re not part of its interface.
Unity uses a programming mechanism called reflection to check for the appearance of these special functions like Start, Update, Awake and so on. Simply put the Unity engine has predefined function naming conventions that it’s trying to find in classes that subclass MonoBehaviour.

So you are not overriding anything from MonoBehaviour, but actually providing the functions for it.

Unity uses reflection into your class to identify any special methods (Start, Update, OnApplicationQuit, etc) that you’ve defined. It will only invoke those methods. Given the number of special methods that MonoBehaviours support, it would be very inefficient to invoke every single one on every single script if they were all defined as virtual methods, especially since most of them wouldn’t be overridden and would just be empty methods providing nothing but unnecessary overhead.