Search Unity

  1. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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

Discussion in 'Data Oriented Technology Stack' started by Mr-Mechanical, Feb 2, 2019.

  1. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    479
    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:
    2,279
    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:
    650
    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:
    479
    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.
unityunity