UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AIController.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
9#include "EngineDefines.h"
10#if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_4
12#endif
13#include "AITypes.h"
15#include "GameplayTask.h"
16#include "GameFramework/Pawn.h"
21#include "AIController.generated.h"
22
25class UBehaviorTree;
26class UBlackboardComponent;
27class UBlackboardData;
28class UBrainComponent;
29class UCanvas;
31class UGameplayTasksComponent;
33
34namespace EPathFollowingRequestResult { enum Type : int; }
35namespace EPathFollowingResult { enum Type : int; }
36namespace EPathFollowingStatus { enum Type : int; }
37
38#if ENABLE_VISUAL_LOG
39struct FVisualLogEntry;
40#endif // ENABLE_VISUAL_LOG
44
46
47// the reason for this being namespace instead of a regular enum is
48// so that it can be expanded in game-specific code
49// @todo this is a bit messy, needs to be refactored
51{
52 typedef uint8 Type;
53
54 inline const Type Default = 0;
55 inline const Type Move = 1;
56 inline const Type Gameplay = 2;
57
59}
60
77
78//~=============================================================================
89UCLASS(ClassGroup = AI, BlueprintType, Blueprintable, MinimalAPI)
91{
93
94 FGameplayResourceSet ScriptClaimedResources;
95protected:
97
100 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AI)
101 uint32 bStartAILogicOnPossess : 1;
102
105 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AI)
106 uint32 bStopAILogicOnUnposses : 1;
107
108public:
110 UPROPERTY()
111 mutable uint32 bLOSflag : 1;
112
114 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AI)
115 uint32 bSkipExtraLOSChecks : 1;
116
118 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AI)
119 uint32 bAllowStrafe : 1;
120
122 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AI)
123 uint32 bWantsPlayerState : 1;
124
126 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AI)
127 uint32 bSetControlRotationFromPawnOrientation:1;
128
129private:
130
132 UPROPERTY(VisibleDefaultsOnly, Category = AI)
133 TObjectPtr<UPathFollowingComponent> PathFollowingComponent;
134
135public:
136
138 UPROPERTY(BlueprintReadWrite, Category = AI)
140
141 UPROPERTY(VisibleDefaultsOnly, Category = AI)
142 TObjectPtr<UAIPerceptionComponent> PerceptionComponent;
143
146 UPROPERTY(BlueprintReadOnly, Category = AI, meta = (AllowPrivateAccess = "true"))
147 TObjectPtr<UBlackboardComponent> Blackboard;
148
149 UPROPERTY()
150 TObjectPtr<UGameplayTasksComponent> CachedGameplayTasksComponent;
151
152 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = AI)
153 TSubclassOf<UNavigationQueryFilter> DefaultNavigationFilterClass;
154
155public:
156
158
159 AIMODULE_API virtual void SetPawn(APawn* InPawn) override;
160
170 UFUNCTION(BlueprintCallable, Category = "AI|Navigation", Meta = (AdvancedDisplay = "bStopOnOverlap,bCanStrafe,bAllowPartialPath"))
171 AIMODULE_API EPathFollowingRequestResult::Type MoveToActor(AActor* Goal, float AcceptanceRadius = -1, bool bStopOnOverlap = true,
172 bool bUsePathfinding = true, bool bCanStrafe = true,
173 TSubclassOf<UNavigationQueryFilter> FilterClass = {}, bool bAllowPartialPath = true);
174
185 UFUNCTION(BlueprintCallable, Category = "AI|Navigation", Meta = (AdvancedDisplay = "bStopOnOverlap,bCanStrafe,bAllowPartialPath"))
186 AIMODULE_API EPathFollowingRequestResult::Type MoveToLocation(const FVector& Dest, float AcceptanceRadius = -1, bool bStopOnOverlap = true,
187 bool bUsePathfinding = true, bool bProjectDestinationToNavigation = false, bool bCanStrafe = true,
188 TSubclassOf<UNavigationQueryFilter> FilterClass = {}, bool bAllowPartialPath = true);
189
195 AIMODULE_API virtual FPathFollowingRequestResult MoveTo(const FAIMoveRequest& MoveRequest, FNavPathSharedPtr* OutPath = nullptr);
196
198 AIMODULE_API virtual FAIRequestID RequestMove(const FAIMoveRequest& MoveRequest, FNavPathSharedPtr Path);
199
205 AIMODULE_API virtual void FindPathForMoveRequest(const FAIMoveRequest& MoveRequest, FPathFindingQuery& Query, FNavPathSharedPtr& OutPath) const;
206
208 AIMODULE_API bool BuildPathfindingQuery(const FAIMoveRequest& MoveRequest, FPathFindingQuery& OutQuery) const;
209
211 AIMODULE_API bool BuildPathfindingQuery(const FAIMoveRequest& MoveRequest, const FVector& StartLocation, FPathFindingQuery& OutQuery) const;
212
213 UE_DEPRECATED_FORGAME(4.13, "This function is now deprecated, please use FindPathForMoveRequest() for adjusting Query or BuildPathfindingQuery() for getting one.")
215
216 UE_DEPRECATED_FORGAME(4.13, "This function is now deprecated, please use FindPathForMoveRequest() for adjusting pathfinding or path postprocess.")
217 AIMODULE_API virtual FAIRequestID RequestPathAndMove(const FAIMoveRequest& MoveRequest, FPathFindingQuery& Query);
218
221
224
226 AIMODULE_API virtual void StopMovement() override;
227
229 AIMODULE_API virtual void OnMoveCompleted(FAIRequestID RequestID, const FPathFollowingResult& Result);
230
231 UE_DEPRECATED_FORGAME(4.13, "This function is now deprecated, please use version with EPathFollowingResultDetails parameter.")
232 AIMODULE_API virtual void OnMoveCompleted(FAIRequestID RequestID, EPathFollowingResult::Type Result);
233
235 AIMODULE_API FAIRequestID GetCurrentMoveRequestID() const;
236
238 UPROPERTY(BlueprintAssignable, meta = (DisplayName = "MoveCompleted"))
239 FAIMoveCompletedSignature ReceiveMoveCompleted;
240
241 TSubclassOf<UNavigationQueryFilter> GetDefaultNavigationFilterClass() const { return DefaultNavigationFilterClass; }
242
244 UFUNCTION(BlueprintCallable, Category = "AI|Navigation")
245 AIMODULE_API EPathFollowingStatus::Type GetMoveStatus() const;
246
248 UFUNCTION(BlueprintCallable, Category = "AI|Navigation")
249 AIMODULE_API bool HasPartialPath() const;
250
252 UFUNCTION(BlueprintCallable, Category = "AI|Navigation")
253 AIMODULE_API FVector GetImmediateMoveDestination() const;
254
256 UFUNCTION(BlueprintCallable, Category = "AI|Navigation")
257 AIMODULE_API void SetMoveBlockDetection(bool bEnable);
258
260 UFUNCTION(BlueprintCallable, Category = "AI")
261 AIMODULE_API virtual bool RunBehaviorTree(UBehaviorTree* BTAsset);
262
264 AIMODULE_API virtual void CleanupBrainComponent();
265
268
269public:
276 UFUNCTION(BlueprintCallable, Category = "AI")
277 AIMODULE_API bool UseBlackboard(UBlackboardData* BlackboardAsset, UBlackboardComponent*& BlackboardComponent);
278
280 AIMODULE_API virtual bool ShouldSyncBlackboardWith(const UBlackboardComponent& OtherBlackboardComponent) const;
281
282 UFUNCTION(BlueprintCallable, Category = "AI|Tasks")
284
285 UFUNCTION(BlueprintCallable, Category = "AI|Tasks")
287
289 UFUNCTION(BlueprintImplementableEvent)
290 AIMODULE_API void OnUsingBlackBoard(UBlackboardComponent* BlackboardComp, UBlackboardData* BlackboardAsset);
291
292 AIMODULE_API virtual bool InitializeBlackboard(UBlackboardComponent& BlackboardComp, UBlackboardData& BlackboardAsset);
293
294public:
296 UFUNCTION(BlueprintCallable, Category = "AI")
297 AIMODULE_API FVector GetFocalPoint() const;
298
299 AIMODULE_API FVector GetFocalPointForPriority(EAIFocusPriority::Type InPriority) const;
300
302 UFUNCTION(BlueprintCallable, Category = "AI")
303 AIMODULE_API virtual FVector GetFocalPointOnActor(const AActor *Actor) const;
304
306 UFUNCTION(BlueprintCallable, Category = "AI", meta = (DisplayName = "SetFocalPoint", ScriptName = "SetFocalPoint", Keywords = "focus"))
307 AIMODULE_API void K2_SetFocalPoint(FVector FP);
308
310 UFUNCTION(BlueprintCallable, Category = "AI", meta = (DisplayName = "SetFocus", ScriptName = "SetFocus"))
311 AIMODULE_API void K2_SetFocus(AActor* NewFocus);
312
314 UFUNCTION(BlueprintCallable, Category = "AI")
315 AIMODULE_API AActor* GetFocusActor() const;
316
317 inline AActor* GetFocusActorForPriority(EAIFocusPriority::Type InPriority) const { return FocusInformation.Priorities.IsValidIndex(InPriority) ? FocusInformation.Priorities[InPriority].Actor.Get() : nullptr; }
318
320 UFUNCTION(BlueprintCallable, Category = "AI", meta = (DisplayName = "ClearFocus", ScriptName = "ClearFocus"))
321 AIMODULE_API void K2_ClearFocus();
322
323
336 AIMODULE_API bool SuggestTossVelocity(FVector& OutTossVelocity, FVector Start, FVector End, float TossSpeed, bool bPreferHighArc, float CollisionRadius = 0, bool bOnlyTraceUp = false);
337
338 //~ Begin AActor Interface
339 AIMODULE_API virtual void Tick(float DeltaTime) override;
340 AIMODULE_API virtual void PostInitializeComponents() override;
341 AIMODULE_API virtual void PostRegisterAllComponents() override;
342 //~ End AActor Interface
343
344 //~ Begin AController Interface
346 AIMODULE_API virtual void OnPossess(APawn* InPawn) override;
347 AIMODULE_API virtual void OnUnPossess() override;
348
349public:
350 AIMODULE_API virtual bool ShouldPostponePathUpdates() const override;
351 AIMODULE_API virtual void DisplayDebug(UCanvas* Canvas, const FDebugDisplayInfo& DebugDisplay, float& YL, float& YPos) override;
352
353#if ENABLE_VISUAL_LOG
354 AIMODULE_API virtual void GrabDebugSnapshot(FVisualLogEntry* Snapshot) const override;
355#endif
356
357 AIMODULE_API virtual void Reset() override;
358
366 AIMODULE_API virtual bool LineOfSightTo(const AActor* Other, FVector ViewPoint = FVector(ForceInit), bool bAlternateChecks = false) const override;
367 //~ End AController Interface
368
370 AIMODULE_API virtual void ActorsPerceptionUpdated(const TArray<AActor*>& UpdatedActors);
371
373 AIMODULE_API virtual void UpdateControlRotation(float DeltaTime, bool bUpdatePawn = true);
374
377
378 /* Set Focus actor for given priority, will set FocalPoint as a result. */
380
383 AIMODULE_API virtual void ClearFocus(EAIFocusPriority::Type InPriority);
384
385 AIMODULE_API void SetPerceptionComponent(UAIPerceptionComponent& InPerceptionComponent);
386 //----------------------------------------------------------------------//
387 // IAIPerceptionListenerInterface
388 //----------------------------------------------------------------------//
389 virtual UAIPerceptionComponent* GetPerceptionComponent() override { return GetAIPerceptionComponent(); }
390
391 //----------------------------------------------------------------------//
392 // INavAgentInterface
393 //----------------------------------------------------------------------//
394 AIMODULE_API virtual bool IsFollowingAPath() const override;
395 AIMODULE_API virtual IPathFollowingAgentInterface* GetPathFollowingAgent() const override;
396
397 //----------------------------------------------------------------------//
398 // IGenericTeamAgentInterface
399 //----------------------------------------------------------------------//
400private:
401 FGenericTeamId TeamID;
402public:
403 AIMODULE_API virtual void SetGenericTeamId(const FGenericTeamId& NewTeamID) override;
404 virtual FGenericTeamId GetGenericTeamId() const override { return TeamID; }
405
406 //----------------------------------------------------------------------//
407 // IGameplayTaskOwnerInterface
408 //----------------------------------------------------------------------//
409 virtual UGameplayTasksComponent* GetGameplayTasksComponent(const UGameplayTask& Task) const override { return GetGameplayTasksComponent(); }
410 virtual AActor* GetGameplayTaskOwner(const UGameplayTask* Task) const override { return const_cast<AAIController*>(this); }
411 virtual AActor* GetGameplayTaskAvatar(const UGameplayTask* Task) const override { return GetPawn(); }
413
414 inline UGameplayTasksComponent* GetGameplayTasksComponent() const { return CachedGameplayTasksComponent; }
415
416 // add empty overrides to fix linker errors if project implements a child class without adding GameplayTasks module dependency
418 virtual void OnGameplayTaskActivated(UGameplayTask& Task) override {}
420
421 UFUNCTION()
423
424 //----------------------------------------------------------------------//
425 // debug/dev-time
426 //----------------------------------------------------------------------//
427 AIMODULE_API virtual FString GetDebugIcon() const;
428
429 // Cheat/debugging functions
430 static void ToggleAIIgnorePlayers() { bAIIgnorePlayers = !bAIIgnorePlayers; }
431 static bool AreAIIgnoringPlayers() { return bAIIgnorePlayers; }
432
435
436public:
438 UFUNCTION(BlueprintCallable, Category="AI|Navigation")
439 UPathFollowingComponent* GetPathFollowingComponent() const { return PathFollowingComponent; }
440 UFUNCTION(BlueprintPure, Category = "AI|Perception")
441 UAIPerceptionComponent* GetAIPerceptionComponent() { return PerceptionComponent; }
442
443 const UAIPerceptionComponent* GetAIPerceptionComponent() const { return PerceptionComponent; }
444
445 UBrainComponent* GetBrainComponent() const { return BrainComponent; }
446 const UBlackboardComponent* GetBlackboardComponent() const { return Blackboard; }
447 UBlackboardComponent* GetBlackboardComponent() { return Blackboard; }
448
451 UFUNCTION(BlueprintCallable, Category = "AI|Navigation")
452 AIMODULE_API void SetPathFollowingComponent(UPathFollowingComponent* NewPFComponent);
453};
454
455//----------------------------------------------------------------------//
456// forceinlines
457//----------------------------------------------------------------------//
458namespace FAISystem
459{
461 {
462 return Controller != nullptr && Controller->IsPendingKillPending() == false
463 && Controller->GetPawn() != nullptr && Controller->GetPawn()->IsPendingKillPending() == false;
464 }
465}
OODEFFUNC typedef const int const char * function
Definition oodle2.h:710
#define UE_DEPRECATED_FORGAME
Definition CoreMiscDefines.h:377
@ ForceInit
Definition CoreMiscDefines.h:155
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(DelegateName, Param1Type, Param1Name, Param2Type, Param2Name)
Definition DelegateCombinations.h:62
return true
Definition ExternalRpcRegistry.cpp:601
#define FVector
Definition IOSSystemIncludes.h:8
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UFUNCTION(...)
Definition ObjectMacros.h:745
#define UCLASS(...)
Definition ObjectMacros.h:776
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition AIController.h:91
virtual FGenericTeamId GetGenericTeamId() const override
Definition AIController.h:404
virtual UGameplayTasksComponent * GetGameplayTasksComponent(const UGameplayTask &Task) const override
Definition AIController.h:409
virtual uint8 GetGameplayTaskDefaultPriority() const
Definition AIController.h:412
virtual void OnGameplayTaskActivated(UGameplayTask &Task) override
Definition AIController.h:418
const UBlackboardComponent * GetBlackboardComponent() const
Definition AIController.h:446
virtual void OnGameplayTaskInitialized(UGameplayTask &Task) override
Definition AIController.h:417
FFocusKnowledge FocusInformation
Definition AIController.h:96
virtual AActor * GetGameplayTaskOwner(const UGameplayTask *Task) const override
Definition AIController.h:410
UBrainComponent * GetBrainComponent() const
Definition AIController.h:445
UBlackboardComponent * GetBlackboardComponent()
Definition AIController.h:447
static bool AreAIIgnoringPlayers()
Definition AIController.h:431
UGameplayTasksComponent * GetGameplayTasksComponent() const
Definition AIController.h:414
const UAIPerceptionComponent * GetAIPerceptionComponent() const
Definition AIController.h:443
UE_DEPRECATED_FORGAME(4.13, "This function is now deprecated, please use FindPathForMoveRequest() for adjusting Query or BuildPathfindingQuery() for getting one.") AIMODULE_API virtual bool PreparePathfinding(const FAIMoveRequest &MoveRequest
virtual UAIPerceptionComponent * GetPerceptionComponent() override
Definition AIController.h:389
virtual AActor * GetGameplayTaskAvatar(const UGameplayTask *Task) const override
Definition AIController.h:411
virtual void OnGameplayTaskDeactivated(UGameplayTask &Task) override
Definition AIController.h:419
static AIMODULE_API bool bAIIgnorePlayers
Definition AIController.h:434
Definition Actor.h:257
Definition Controller.h:41
Definition DisplayDebugHelpers.h:9
Definition UObjectGlobals.h:1292
Definition AIPerceptionListenerInterface.h:19
Definition GameplayTaskOwnerInterface.h:21
Definition GenericTeamAgentInterface.h:82
Definition PathFollowingAgentInterface.h:21
Definition VisualLoggerDebugSnapshotInterface.h:17
Definition Array.h:670
Definition SubclassOf.h:30
Definition BehaviorTree.h:16
Definition BlackboardData.h:46
Definition BrainComponent.h:118
Definition Canvas.h:159
Definition GameplayTaskResource.h:15
Definition GameplayTask.h:146
Definition NavigationQueryFilter.h:107
Definition PathFollowingComponent.h:217
Definition AIController.h:51
uint8 Type
Definition AIController.h:52
const Type LastFocusPriority
Definition AIController.h:58
const Type Move
Definition AIController.h:55
const Type Gameplay
Definition AIController.h:56
const Type Default
Definition AIController.h:54
Definition AIController.h:34
Type
Definition PathFollowingComponent.h:157
Definition AIController.h:35
Type
Definition PathFollowingComponent.h:56
Definition AIController.h:36
Type
Definition PathFollowingComponent.h:37
Definition AIController.h:459
bool IsValidControllerAndHasValidPawn(const AController *Controller)
Definition AIController.h:460
constexpr FVector InvalidLocation
Definition AITypes.h:30
constexpr uint8 DefaultPriority
Definition GameplayTaskTypes.h:16
@ false
Definition radaudio_common.h:23
Definition AITypes.h:462
Definition AITypes.h:403
Definition AIController.h:64
TWeakObjectPtr< AActor > Actor
Definition AIController.h:65
FFocusItem()
Definition AIController.h:68
FVector Position
Definition AIController.h:66
Definition AIController.h:62
TArray< FFocusItem > Priorities
Definition AIController.h:75
Definition GameplayTask.h:46
Definition GenericTeamAgentInterface.h:24
Definition NavigationSystemTypes.h:62
Definition PathFollowingComponent.h:165
Definition PathFollowingComponent.h:122
Definition VisualLoggerTypes.h:205
Definition ObjectPtr.h:488
Definition WeakObjectPtrTemplates.h:25