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.

cpp
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.

cpp
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 pendingImages/CrimsonTeams/howto-observe-team.png
Observe Team Colors (Team Agent = the PlayerState) -> On Team Changed -> apply the Display Asset to your nameplate material.
Verify
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