Search Unity

ECS/MonoBehaviour Order of Execution

Discussion in 'Entity Component System' started by DreamersINC, Jan 12, 2020.

  1. DreamersINC

    DreamersINC

    Joined:
    Mar 4, 2015
    Posts:
    131
    Should the Awake function of a monobehaviour be call before the OnUpdate of a ComponentSystem and before Entity Conversion takes place? Is there a better why than setting all the script execution order make sure this does happen?
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
    Script Execution Order won't help you because systems get called at different points in the player loop.
     
  3. DreamersINC

    DreamersINC

    Joined:
    Mar 4, 2015
    Posts:
    131
    So I need to add a null check in OnUpdate
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    The way to ensure, you have control over ECS system execution, is to execute them manually.
    Otherwise, Monobehaviour and ECS systems execution orders are not correlated in anyway.
     
  5. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    I think simulation group which is the default destination of system already ensure it comes after all MonoBehaviour. This default suggest they want you to be able to interface from mono to ECS in the same frame but not the other way. (For that you could use intiialization group)
     
    Last edited: Jan 12, 2020
  6. DreamersINC

    DreamersINC

    Joined:
    Mar 4, 2015
    Posts:
    131
    Based on my work, OnCreate and Covert happen either with or before Awake. I have debugged a few null ref and no value components to find that out.