RealDocs

AAIController::GetGameplayTasksComponent

function AIModule Since 4.0
#include "AIController.h"
Access: public Specifiers: inlineconst

Description

Returns the cached UGameplayTasksComponent for this controller, used to manage and run UGameplayTask instances. Returns null if no such component is present.

Caveats & Gotchas

  • The pointer is cached in PostRegisterAllComponents via FindComponentByClass. If a UGameplayTasksComponent is added dynamically at runtime after registration, the cache will be stale and this function will return null until the component is re-registered.
  • There are two overloads: this no-argument inline version (for direct access) and an IGameplayTaskOwnerInterface virtual override that accepts a UGameplayTask& argument. Both return the same component, but the interface version is needed for task system callbacks.

Signature

inline UGameplayTasksComponent* GetGameplayTasksComponent() const

Return Type

UGameplayTasksComponent*

Example

Guard gameplay task activation C++
void AMyAIController::TryActivateTask()
{
	UGameplayTasksComponent* TasksComp = GetGameplayTasksComponent();
	if (!TasksComp)
	{
		return;
	}
	UGameplayTask_ClaimResource* Task = UGameplayTask::NewTask<UGameplayTask_ClaimResource>(this);
	TasksComp->AddTaskReadyForActivation(*Task);
}

Tags

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.