Search Unity

[SOLVED] [ECS Bootstrap Initilization] Is OnCreateManager Called before Start() in MonoBehaviour?

Discussion in 'Entity Component System' started by Mr-Mechanical, Feb 2, 2019.

  1. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    507
    Hi,

    I am looking into initializing some data for my ECS systems. I have some data copied from BootStrap Initialization MonoBehaviour into a system with OnCreateManager. Though, I am having some issues with this. Any chance OnCreateManager with systems is called before MonoBehaviour Start()? This would explain my issues.

    Any help is well appreciated. Thanks a lot.
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    OnCreateManager is called as soon as the system is created.

    When using default world initialization, this happens in RuntimeInitializeLoadType.BeforeSceneLoad
     
    xVergilx and Mr-Mechanical like this.
  3. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    You can define a regular constructor on a system and pass data to it if you use
    CreateManager<T>(params object[] args)
    (the arguments will be boxed). OnCreateManager has to run after the constructor.

    You must also ensure the system has the
    [DisableAutoCreation]
    attribute.
     
    learc83 and Mr-Mechanical like this.
  4. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    507
    Thanks tertle and recursive for sharing your knowledge about this. This will come in handy. I'm trying to create a persistent NativeArray of Entites for use in a system (therefore the order of entities can be altered efficiently). The problem seems is that the initialization of the NativeArray in OnCreateManager comes too early before the BootStrap's Start() method runs. The BootStrap's Start() method has a NativeList which adds the relevant entities. The current idea is intializing the NativeArray from the NativeList created by the BootStrap. I'm trying to think of a working way to do this. Thanks for the input so far.
     
    recursive likes this.