Search Unity

Best way to initialize Singleton data

Discussion in 'Entity Component System' started by PublicEnumE, Aug 21, 2019.

  1. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    Whats the best way to go about setting up Singleton component data at the start of your game?

    I’m hesitant to write a system just to configure this data, since it will only ever need to run once. If a create a system, won’t Unity continue to consider it for updates for the entire runtime?

    Other options that leaves: ICustomBootstrap (which seems like the wrong tool for this job), and perhaps the RuntimeInitializeOnLoadAttribute.

    If you needed to setup some Singleton data at the start of your project, how would you do it?

    Thanks for any advice.
     
    Last edited: Aug 21, 2019
  2. recursive

    recursive

    Joined:
    Jul 12, 2012
    Posts:
    669
    I've created this framework for simplifying setup/conversion of configuration ScriptableObjects -> ECS Singletons, with support for destruction/reloading: https://github.com/periodyctom/Hydrogen.Entities

    I need to add test/samples and make it more compatible with ECS SubScenes, all of which are on my docket this week.

    It does work as a hybrid solution currently, as that's how I load my Game and input system configuration data.
     
    PublicEnumE likes this.