Search Unity

Bootstrap code in rotation sample?

Discussion in 'Entity Component System' started by Krajca, Mar 20, 2018.

  1. Krajca

    Krajca

    Joined:
    May 6, 2014
    Posts:
    347
    As above: is there bootstrap code in mentioned example? If there's not then where entity manager is created?
     
  2. HelloMeow

    HelloMeow

    Joined:
    May 11, 2014
    Posts:
    280
    It's all done automatically, through AutomaticWorldBootstrap.Initialize and GameObjectEntity.OnEnable.

    Either AutomaticWorldBootstrap or GameObjectEntity calls DefaultWorldInitialization.Initialize, which then creates an instance for each type that derives from ComponentSystemBase. Unless the type has the DisableAutoCreation attribute.

    Then the EntityManager is retrieved in ComponentSystem.OnBeforeCreateManagerInternal.
     
    Krajca likes this.
  3. Krajca

    Krajca

    Joined:
    May 6, 2014
    Posts:
    347
    Oh I see. ComponentSystem provides reference to default EntityManager. So you can use that or initialize it in bootstrap (like in two stick shooter sample) Am I right?
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    When entering Playmode, we automatically create a system an inject all component systems into it.

    For some games you might want to control system creation, create multiple worlds etc. So you can use this define to turn the default behaviour off.

    UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP

    And then use [RuntimeInitializeOnLoadMethod] to control the boostrapping code of your world & EntityManager


    The GameObjectEntity in the editor automatically creates an Editor world. Only systems with [ExecuteInEditMode] will be created in the editor world. (This behaviour happens only in edit mode, not in playmode)


     
    SugoiDev and Krajca like this.
  5. Krajca

    Krajca

    Joined:
    May 6, 2014
    Posts:
    347
    For some reasons I can't find this define in two sticks shooter project (pure version) but it have a bootstrap code. So, it's like partially default, partially custom initialization, yes?
    Should I use bootstrap for app initialization, like main setting, resource load etc.?
     
  6. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    The code I pasted above is part of the Entity Component System package. So if you put the UNITY_DISABLE_AUTOMATIC_SYSTEM_BOOTSTRAP in player settings global defines, then it will turn off the automatic bootstrap and you can fully create world creation etc

    We will add more documentation on this topic.