CrimsonTeams · Lesson 3 of 6

Gate Damage & Filter Targets

Intermediate4 minGameplayGAS

Before you start

  • Completed: Agents & Attitude
Video coming soon

Chapters

Gate friendly fire

ShouldCauseDamageToTarget is the quick bool — true for Hostile or Neutral, false for Friendly. The subsystem variant adds a self-damage flag.

cpp
// Friendly-fire gate (true for Hostile or Neutral; false for Friendly):
const bool bCanDamage = UCrimsonTeamStatics::ShouldCauseDamageToTarget(Source, Target);
// Subsystem variant with a self-damage flag:
UCrimsonTeamSubsystem* TS = GetWorld()->GetSubsystem<UCrimsonTeamSubsystem>();
const bool bCan = TS->CanCauseDamage(Instigator, Target, /*bAllowDamageToSelf*/ true);
Check at apply-time, not activation-time
Attitude is dynamic — a target can change teams mid-ability. Evaluate it when the hit actually lands, not when the ability starts, so a freshly-turned enemy (or ally) is judged correctly.

Filter ability targets by attitude

MakeFilteredTargetDataFromActors keeps only the actors matching a filter and packages them as a FGameplayAbilityTargetDataHandle (self and nulls always excluded) — ideal for AoE.

ECrimsonTargetFilterKeeps
HostileAndNeutralDamage abilities (default)
HostileOnlyEnemy-only attacks
FriendlyAndNeutralSupport abilities
FriendlyOnlyHeals / buffs
AllIndiscriminate effects
cpp
FGameplayAbilityTargetDataHandle Data =
UCrimsonTeamStatics::MakeFilteredTargetDataFromActors(
AbilityOwner, OverlappingActors, ECrimsonTargetFilter::HostileAndNeutral);