void UGameplayTasksComponent::OnGameplayTaskActivated(UGameplayTask& Task) { // process events after finishing all operations FEventLock ScopeEventLock(this); if (Task.IsTickingTask()) { check(TickingTasks.Contains(&Task) == false); TickingTasks.Add(&Task); // If this is our first ticking task, set this component as active so it begins ticking if (TickingTasks.Num() == 1) { UpdateShouldTick(); } } if (Task.IsSimulatedTask()) { check(SimulatedTasks.Contains(&Task) == false); SimulatedTasks.Add(&Task); } IGameplayTaskOwnerInterface* TaskOwner = Task.GetTaskOwner(); if (!Task.IsOwnedByTasksComponent() && TaskOwner) { TaskOwner->OnGameplayTaskActivated(Task); } }
void UGameplayTasksComponent::OnGameplayTaskDeactivated(UGameplayTask& Task) { // process events after finishing all operations FEventLock ScopeEventLock(this); const bool bIsFinished = (Task.GetState() == EGameplayTaskState::Finished); if (Task.GetChildTask() && bIsFinished) { if (Task.HasOwnerFinished()) { Task.GetChildTask()->TaskOwnerEnded(); } else { Task.GetChildTask()->EndTask(); } } if (Task.IsTickingTask()) { // If we are removing our last ticking task, set this component as inactive so it stops ticking TickingTasks.RemoveSingleSwap(&Task); } if (Task.IsSimulatedTask()) { SimulatedTasks.RemoveSingleSwap(&Task); } // Resource-using task if (Task.RequiresPriorityOrResourceManagement() && bIsFinished) { OnTaskEnded(Task); } IGameplayTaskOwnerInterface* TaskOwner = Task.GetTaskOwner(); if (!Task.IsOwnedByTasksComponent() && !Task.HasOwnerFinished() && TaskOwner) { TaskOwner->OnGameplayTaskDeactivated(Task); } UpdateShouldTick(); }
void UGameplayTask::InitTask(IGameplayTaskOwnerInterface& InTaskOwner, uint8 InPriority) { Priority = InPriority; TaskOwner = InTaskOwner; UGameplayTasksComponent* GTComponent = InTaskOwner.GetGameplayTasksComponent(*this); TasksComponent = GTComponent; bOwnedByTasksComponent = (TaskOwner == GTComponent); TaskState = EGameplayTaskState::AwaitingActivation; if (bClaimRequiredResources) { ClaimedResources.AddSet(RequiredResources); } InTaskOwner.OnTaskInitialized(*this); if (bOwnedByTasksComponent == false && GTComponent != nullptr) { GTComponent->OnTaskInitialized(*this); } }
void UGameplayTask::InitTask(IGameplayTaskOwnerInterface& InTaskOwner, uint8 InPriority) { Priority = InPriority; TaskOwner = InTaskOwner; TaskState = EGameplayTaskState::AwaitingActivation; if (bClaimRequiredResources) { ClaimedResources.AddSet(RequiredResources); } // call owner.OnGameplayTaskInitialized before accessing owner.GetGameplayTasksComponent, this is required for child tasks InTaskOwner.OnGameplayTaskInitialized(*this); UGameplayTasksComponent* GTComponent = InTaskOwner.GetGameplayTasksComponent(*this); TasksComponent = GTComponent; bOwnedByTasksComponent = (TaskOwner == GTComponent); // make sure that task component knows about new task if (GTComponent && !bOwnedByTasksComponent) { GTComponent->OnGameplayTaskInitialized(*this); } }
void UAITask::InitAITask(AAIController& AIOwner, IGameplayTaskOwnerInterface& InTaskOwner) { InitAITask(AIOwner, InTaskOwner, InTaskOwner.GetGameplayTaskDefaultPriority()); }