Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Resolved How to set singleton component data before system OnCreate()

Discussion in 'DOTS Dev Blitz Day 2022 - Q&A' started by pbhogan, Dec 8, 2022.

  1. pbhogan

    pbhogan

    Joined:
    Aug 17, 2012
    Posts:
    379
    What is the best practice to get some predefined configuration values or other data from a MonoBehavior to available during system OnCreate? Is it just not possible?

    It appears that baked entities are not present by the time systems are created. So, baking some configuration data (similar to PhysicsStep, for example) as an entity doesn't help. You end up having to do a TryGetSingleton() check in OnUpdate and do some initialization there, and so on for every other system that needs that setup data. It seems less than ideal to have a bunch of initialization code in update functions.
     
    baptistee and CookieStealer2 like this.
  2. jivalenzuela

    jivalenzuela

    Unity Technologies

    Joined:
    Dec 4, 2019
    Posts:
    76
    We have plans to revisit it in the upcoming year, but for now I recommend putting the initialization in
    OnStartRunning
    and read it from a
    ScriptableObject
    or other serializable data source.
     
    baptistee and SolidAlloy like this.