Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Lifecycle Question: Calls to Update() before Start() completed

Discussion in 'Scripting' started by wiredninja, Apr 13, 2022.

  1. wiredninja

    wiredninja

    Joined:
    Jul 5, 2021
    Posts:
    15
    EDIT:

    Please ignore this question, I made a mistake with my logic. The following question is obsolete.

    ORIGINAL POST:

    Hi,

    I'm having a
    class Init : MonoBehaviour
    that contains a bunch of events, which are fired during
    Init.Start()
    Others subscribe to those events as to organize the Startup of a scene.

    Now I'm logging
    Init.Update()
    during startup (determined by a
    bool initComplete
    which changes, once Init.Start() completes) and it turns out, that multiple calls to
    Init.Update()
    occur, before
    Init.Start()
    has completed.

    I expected that this would be impossible, is there somebody who can explain this behavior to me?

    Btw, none of my code is async and there is currently only one Scene, so all this happens when starting the game. And obviously I don't reference static methods in the text above, but the actual event-functions of any monobehaviour instance.
     
    Last edited: Apr 13, 2022
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,951
  3. wiredninja

    wiredninja

    Joined:
    Jul 5, 2021
    Posts:
    15
    Hi Kurt,

    Thank you for those links, and sorry for my late reply!

    I'm quite familiar with the lifecycle diagram, which is why I got so confused in the first place, when all values seemed to "jump" beyond the possible range of a single Update() call on startup. It turned out, that during the first Update(), Time.deltaTime includes the duration of the game's initialization time (ofc it does, facepalm!) and I didn't factor that little fact in... then I placed my Debug.Log() in the wrong scope and got a false positive confirmation that Update() got called multiple times ^^

    Stupid little mistakes, right?
     
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,184
    I don't consider it stupid when the documentation makes no mention of it.
     
  5. wiredninja

    wiredninja

    Joined:
    Jul 5, 2021
    Posts:
    15
    Ryiah, seems like you're right in that there's no info about that in the docs.

    So maybe this thread will be helpful to someone after all.