AAIController::GetBrainComponent
#include "AIController.h"
Access: public
Specifiers: const
Description
Returns the UBrainComponent currently driving this controller's AI logic, or null if none is active. Prefer this over accessing BrainComponent directly in C++.
Caveats & Gotchas
- • Returns a base UBrainComponent pointer; cast to UBehaviorTreeComponent if you need behavior-tree-specific methods. The cast can fail if a custom non-BT brain is in use — always check the cast result.
- • The underlying BrainComponent property is BlueprintReadWrite, meaning a Blueprint could have nulled or swapped it at any point. This function simply returns the current value with no guards.
Signature
UBrainComponent* GetBrainComponent() const Return Type
UBrainComponent* Example
Pause and resume AI logic around a cutscene C++
void AMyAIController::OnCutsceneStarted()
{
if (UBrainComponent* Brain = GetBrainComponent())
{
Brain->PauseLogic(TEXT("Cutscene"));
}
}
void AMyAIController::OnCutsceneEnded()
{
if (UBrainComponent* Brain = GetBrainComponent())
{
Brain->ResumeLogic(TEXT("Cutscene"));
}
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?