Hey there, custom GameplayTasks only end up in the TaskPriorityQueue if they return true for RequiresPriorityOrResourceManagement(), so:
- Only if they list resources they depend on,
- Or if their class sets bCaresAboutPriority to true
You would also need to call ReadyForActivation() on those tasks to have them enter the priority queue. A quick summary of the priority queue: this feature mainly exists for queueing a list of tasks and if they should be activate and tick in some sorted order: their priority.
The TL;DR of this is that EndAllResourceConsumingTasksOwnedBy() is not relevant for tasks that (1) don’t use resources and (2) don’t make sure of the priority system. Writing your own “End all tasks” function that iterates KnownTasks is perfectly valid.
Another pattern is that some other external owner of the task manages cleaning them up. Gameplay Ability System (GAS) is another user of the GameplayTasksComponent:
- UAbilitySystemComponent derives from UGameplayTasksComponent
- UAbilityTask derives from UGameplayTask
- UGameplayAbility (instance of an ability blueprint) spawns UAbilityTask (ability task nodes in the blueprint)
In GAS, UGameplayAbility manually tracks which tasks it starts in ActiveTasks. When the ability end, it ends its own tasks, see UGameplayAbility::EndAbility():
// Tell all our tasks that we are finished and they should cleanup
for (int32 TaskIdx = ActiveTasks.Num() - 1; TaskIdx >= 0 && ActiveTasks.Num() > 0; --TaskIdx)
{
UGameplayTask* Task = ActiveTasks[TaskIdx];
if (Task)
{
Task->TaskOwnerEnded(); // *** see my notes
}
}
ActiveTasks.Reset(); // Empty the array but don't resize memory, since this object is probably going to be destroyed very soon anyways.
*** TaskOwnerEnded calls both Task->OnDestroy() and GameplayTasksComponent->OnGameplayTaskDeactivated().
So to revisit your questions from the first post:
Q: “Is every system that starts the task supposed to kill the task?”
A: GAS does things this way, so a system managing their started tasks is an intended approach. But not tracking them all and just ending them from a total list (whether PriorityTaskQueue or KnownTasks), is fine too.
Q: If so, why isn’t there a check that it happened?
A: We haven’t needed a catch-all “End all tasks” function because GAS handles and hides the responsibility, and there are no other derived classes from GameplayTasksComponent. But if you have a custom one or are using GameplayTasksComponent directly, it sounds useful to have a catch-all “end all tasks”.
If you run into issues based on the order in which tasks are then ended, you can consider using the priority queue after all by letting task classes set bCaresAboutPriority to trueand return a different value for GetPriority(). Just be aware that highest priority gets activated first but also deactivated first.