Search Unity

System/global data

Discussion in 'Entity Component System' started by snacktime, Jul 12, 2019.

  1. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    I'm running into some issues trying to refactor global data in the context of having systems and hybrid stuff.

    The first one is that I don't see a way to control startup order of systems. OnCreateManager doesn't doesn't follow the system update order. It doesn't even initialize systems by what group they are in. So systems in simulation can have OnCreateManager called before groups in initialization for example.

    Another one is systems get destroyed before Monobehaviour events like OnDisable.

    I thought I'd be able to have a system that holds all of the various config data, but that won't work. I'm pretty much forced to just use a good old singleton.

    Using GetOrCreateSystem seems to be how to get the earliest possible hook for loading stuff. But that creates an implied dependency that if it breaks, it wouldn't be obvious why.

    Are there any other hooks I'm missing that are called earlier I could use for loading data?

    Edit: Wrong forum,this was supposed to go in the DOTS forum. Will wait for mod to move if possible
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
  3. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,269
    Another tip is to subclass ComponentSystemGroup and in its OnCreate, instantiate the systems you want to run in the group and do most of your initialization logic there. Override SortSystemUpdateList to do nothing if you want to maintain the order of the systems that you added them in.
     
    Sarkahn likes this.