#How to properly implement Awake and Start systems in DOTS

1 messages · Page 1 of 1 (latest)

dire leaf
#

Hi, I'm new to DOTS and one thing that I haven't been able to found anywhere is the equivalent of start/awake. I haven't found a default system group that does that so I created my own but its a bit... wonky. Creating 2 system groups that execute one after another once is easy but where it gets more complicated is how to make sure these will execute before the first simulation update. I haven't been able to put them in the initialization system group as entities don't yet exist and I for some reason couldn't make them execute before any of the subgroups of the simulation group. Anyway, here's my code and if anyone can advice me on how to make it cleaner, thanks!

using Unity.Entities;

namespace UnityEngine {
    [UpdateInGroup(typeof(InitializationSystemGroup))]
    public partial class BlockingSystemGroup :SystemBase {
        protected override void OnUpdate()
        {
            World.GetExistingSystemManaged<SimulationSystemGroup>().Enabled=false;
            World.GetExistingSystemManaged<BlockingSystemGroup>().Enabled=false;
        }
    }

    [UpdateInGroup(typeof(PresentationSystemGroup))]
    public partial class StartingSystemGroup :ComponentSystemGroup {
        protected override void OnUpdate()
        {
            base.OnUpdate();
            World.GetExistingSystemManaged<SimulationSystemGroup>().Enabled=true;
            World.GetExistingSystemManaged<StartingSystemGroup>().Enabled=false;
        }
    }

    [UpdateInGroup(typeof(StartingSystemGroup))]
    [UpdateBefore(typeof(StartSystemGroup))]
    public partial class AwakeSystemGroup : ComponentSystemGroup {
        protected override void OnUpdate()
        {
            base.OnUpdate();
        }
    }

    [UpdateInGroup(typeof(StartingSystemGroup))]
    public partial class StartSystemGroup : ComponentSystemGroup {
        protected override void OnUpdate()
        {
            base.OnUpdate();
        }
    }
}
trail venture
#

systems have OnCreate, OnDestroy, OnStartRunning, OnStopRunning methods which I guess are similar to OnAwake(called once, like OnCreate is called once). Creating systemgroups for this doesnt really look like the right avenue

feral spire
#

In ECS, you query for some data, and do the work based on the query result.

#

What you're trying to do can be expressed in pure data transformation.

#

So I'll reinterpret your code in this sense:

#
  1. Awake systems do their work then add a "DoneAwakeTag" to one or some entities.
  2. Start systems query for entities with "DoneAwakeTag" to do their work then add a "DoneStartTag" to the entities.
  3. Other systems query for entities with "DoneStartTag" to do their work.
#

Remember that the order of system update is generally not that important. The important thing is the flow of your data and their dependencies. Data is the most important thing in ECS, not the systems.

trail venture
#

It’s hard to tell exactly what you are trying to do but imo bakers and baking systems should generally cover what awake and onenable do for gameobjects. Though if you share more about what specifically you’re trying to achieve it would help with suggestions