How-To: React to Team Changes
Goal: update gameplay and UI the moment an actor's team or hostility changes - no polling.
Prerequisites
An actor with a team agent component (Quick Start).
1. Per-agent change delegates
Each component exposes OnTeamTagsChanged and OnHostileTagsChanged (both fire with the owning actor and the old/new tags). They fire on the server when you mutate, and on clients when the change replicates - so listeners work everywhere.
Team->OnTeamTagsChanged.AddDynamic(this, &UMyComp::HandleTeamChanged);void UMyComp::HandleTeamChanged(UObject* ChangedActor,const FGameplayTagContainer& OldTags, const FGameplayTagContainer& NewTags){// recolor nameplate, retarget, etc.}
2. Subsystem-wide attitude hook
After any agent changes and the system has refreshed AI perception, UCrimsonTeamSubsystem::OnTeamAttitudeChanged(ChangedActor) broadcasts once. Bind it for custom AI/UI re-evaluation that should run whenever anyone's attitude shifts.
GetWorld()->GetSubsystem<UCrimsonTeamSubsystem>()->OnTeamAttitudeChanged.AddDynamic(this, &UMyAIService::HandleAttitudeChanged);
3. Blueprint async observers (for UI)
For widgets, the async nodes are simplest: they fire immediately with the current state, then on every change. Cancel by calling Cancel() on the returned action.
Screenshot pending
Images/CrimsonTeams/howto-observe-team.pngVerify
Flip a team in the Dev Tools (or via a cheat) and watch the listener fire once, with the new tags.
See also
- Concept: Dynamic Attitude & Multiplayer - what happens between the mutation and your delegate firing
- How-To: Declared Teams & Colors - driving team-colored visuals