Setup Tasks Queue
A tasks queue allows the local player to hold down a key, launch commands on an entity without them taking effect directly but instead having them added to a queue and then executed by the entity in order of launch.
In this guide, we will go through setting up a tasks queue for the demo game villager unit.
1. Enable Tasks Queue
To enable the use of tasks queues in a map scene, navigate to your map scene's hierarchy and find the Task Manager attached to GameManager -> Essential -> Task.
Find the field Tasks Queue Key and assign it with a Control Type to enable tasks queues for entities in the map scene.
The key assigned to the control type is the key required to be held down by the local player while giving commands to an entity so that the commands are not launched directly but rather added to the queue. For example, you can use the Left Shift key as the tasks queue enabling key.
2. Setup Entity Tasks Queue Handler
After enabling tasks queue in the map scene, each individual unit that allows for tasks to be added to a queue must be configured.
Open the villager unit prefab and in the main parent object or one of the children objects, add the Entity Tasks Queue Handler component.
- Make sure Is Active field is enabled.
- Assign a code in the Code field that is unique among other components in the entity, for example tasks_queue.
- Enable the Keep Active Task field to allow the currently active task of an entity to remain active and not be aborted when a new task is added to the empty queue. In case this field is enabled, you can choose to exclude the resource collection tasks from the tasks that an entity is allowed to keep active when a new task is added to the empty queue. The latter option is available since resource collection tasks are active until the target resource is depleted which might take a while to complete.
3. Testing
Now launch the game and launch movement, building placement or resource collection commands (or any command that can have a target entity or destination that can be launched on the villager entity) and tasks will then be added to the the unit's queue and will be launched in order.
When the key used to enable the tasks queue is the same the key used to hold down and spawn multiple buildings, each building construction task that is launched post placement will be then added to the queue and the builder unit will go through all the placed building entities to construct them all in the order they were placed at.
In order to interrupt and clear the tasks queue, you only need to launch a command on the entity without having the tasks queue key held down.