AAIController::GetGameplayTaskAvatar
#include "AIController.h"
Access: public
Specifiers: virtualconstoverride
Description
Returns the visual/physical avatar for gameplay tasks — the currently possessed pawn. Tasks that apply effects to the world (e.g. movement, animation) use this to find the target actor.
Caveats & Gotchas
- • Returns `nullptr` if the controller does not currently possess a pawn. Tasks should guard against a null avatar before accessing components on it.
- • This differs from `GetGameplayTaskOwner`, which returns the controller itself. The distinction matters for tasks that apply gameplay effects — effects should target the avatar, not the owning controller.
Signature
virtual AActor* GetGameplayTaskAvatar(const UGameplayTask* Task) const override { return GetPawn(); } Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Task | const UGameplayTask* | The gameplay task querying its avatar. | — |
Return Type
AActor* Example
Guard against unpossessed state in a custom task C++
void UMyAITask::Activate()
{
AActor* Avatar = GetOwnerActor() ? Cast<IGameplayTaskOwnerInterface>(GetOwnerActor())->GetGameplayTaskAvatar(this) : nullptr;
if (!Avatar)
{
EndTask();
return;
}
// Safe to use Avatar here
} See Also
Tags
Version History
Introduced in: 4.12
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?