How is Start() invoked?

Hello everyone,

From what I’ve learned so far, each time you want to invoke a coroutine you have to use StartCoroutine() to do it.

But when Rick turns Start() into a coroutine, is starts normally (as expected) as soon as the object is instantiated by Unity - but there’s no difference if Start() is a normal function or a coroutine. Unity starts and runs it either way.

When I was doing this lecture I tought, ‘well someone has to start Start() as a coroutine’, so I added an Awake() method to do it:

private void Awake()
    {
        StartCoroutine(Start());
    }

Which I removed later as it is unnecessary.

So, how Unity internally knows how it should call Start() as a normal function or as a coroutine? Does it look first at the Start() method definition first, to know how to call it?

Thanks!

1 Like

A lot of Unity callbacks can be used as Coroutines as long as they return an IEnumerator, the few exceptions are: Awake, Update, LateUpdate, FixedUpdate, OnGUI, OnEnable, OnDisable, OnDestroy.

So, based on that, how Unity handles depends on the return type.

Got it ! Some reference to that info could be made on the course, to explain why in this case (Unity callbacks) StartCoroutine() isn’t necessary.

Thank you!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms