Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Best way to implement a queue of agent actions

Discussion in 'Entity Component System' started by PStringer, Jan 26, 2023.

  1. PStringer

    PStringer

    Joined:
    Aug 21, 2018
    Posts:
    2
    Hi all,

    Does anyone have an advice on how best implement a queued set of actions for a given agent? If thinking about an RTS for example where you queue up a set on different actions like; move here, attack that, them move back over here. I'm very new to DOTs and ECS and I'm struggling to get my head around how to achieve this without some kind of inheritance using a base Action type.

    What I have currently is agents that may have a MoveTo component added to them. The move system then picks that up and moves the agent. Same for Attack etc. pretty standard. Each action is given to the agent one at a time.

    I've to tried get my head around doing it in a few different ways.

    1. An aspect that contains a dynamic list of action Ids or types. Then when one is complete, the next is requested which essentially adds a new component to the agent for that action which it then completes. My problem here is the actions are different and might require different data. So the MoveTo type will need a
    float3 
    position where as an Attack might need an Entity or some other Health type component. Without inheritance I'm struggling to see how I would do this.

    2. A hybrid approach using a singleton Mono ActionScheduler. Essentially it will keep track of the tasks for a particular agent and when the agent is done with a task, another one is set with this. This feels a little more familiar as I can have some kind of map with the Entity and a list of it's actions but it somehow feels wrong.

    3. Similar to the hybrid but using a SingletonComponent that is associated with a ActionScheduleSystem system. Works in much the same way too except it's done in the ECS world. I face the same problem with a generic list of actions though and how best to manage that.

    4. Using a buffer on the entity itself. Problem here again is like the others.. how can I have a generic list of different action types with different additional data.

    Thanks in advance for reading and for any help you can give. Not looking for the solution, just maybe a nudge in the right direction.