CrimsonTeams · Lesson 4 of 6
Wire It to AI
Before you start
- Completed: Agents & Attitude
Chapters
Why AI needs a hand
Unreal's AI perception reads attitude by casting the perceiving actor (the AI's controller or pawn) to IGenericTeamAgentInterface — it never looks at the component. So for affiliation-filtered senses to see Crimson teams, the AI's controller (or pawn) must implement the interface and forward to the tag logic.
The one-method forward
// On your AI controller (or pawn):virtual ETeamAttitude::Type GetTeamAttitudeTowards(const AActor& Other) const override{// Resolve via the controlled pawn, where the team component usually lives.return UCrimsonTeamStatics::GetTeamAttitudeBetween(GetPawn(), &Other);}
Using CrimsonCore? Already done
ACrimsonCharacter, ACrimsonNPCBase, the AI controllers, and ACrimsonPlayerState already implement this forward, so perception reads Crimson attitudes out of the box. You only need this step when you write your own AI classes.Why the interface, not the component
A
UGFA_AddTeams component can't supply an interface — interfaces are compile-time on the class — so this forward lives on your AI controller/pawn, not on a runtime-added component.Dynamic re-aggro
On any team change, the subsystem re-evaluates each AI perceiver via RequestStimuliListenerUpdate — preserving last-known location, no `ForgetActor`. A freshly-hostile actor starts getting perceived and a new ally stops, without losing what the AI already knew. For custom AI/UI re-evaluation, bind the subsystem hook:
GetWorld()->GetSubsystem<UCrimsonTeamSubsystem>()->OnTeamAttitudeChanged.AddDynamic(this, &UMyAIService::HandleAttitudeChanged);