Gameplay Tags
A gameplay tag is a hierarchical name such as Status.Stunned, Ability.Attack.Melee or Damage.Type.Fire, registered once for the whole project. Tags replace the pile of booleans and enums that state tends to become (bIsStunned, bIsBurning, EWeaponType…) with something data-driven: designers add tags in the editor, and code asks questions such as "does this actor have any Status.Debuff tag?".
They are the backbone of the Gameplay Ability System (abilities are blocked by tags, effects grant tags), but they work on their own too. Add the "GameplayTags" module to Build.cs.
Defining tags
Three ways, all ending up in one tag table:
Project Settings → Project → GameplayTags → Manage Gameplay Tags: add tags in the editor. They are saved to
Config/DefaultGameplayTags.ini:ini[/Script/GameplayTags.GameplayTagsSettings] +GameplayTagList=(Tag="Status.Stunned",DevComment="Can't move or act") +GameplayTagList=(Tag="Status.Debuff.Burning",DevComment="") +GameplayTagList=(Tag="Ability.Attack.Melee",DevComment="")Native tags in C++, so code can use them without string lookups (UE 5.x):
cpp// ArenaTags.h #pragma once #include "NativeGameplayTags.h" UE_DECLARE_GAMEPLAY_TAG_EXTERN(TAG_Status_Stunned); UE_DECLARE_GAMEPLAY_TAG_EXTERN(TAG_Ability_Attack_Melee); UE_DECLARE_GAMEPLAY_TAG_EXTERN(TAG_Data_Damage); // ArenaTags.cpp #include "ArenaTags.h" UE_DEFINE_GAMEPLAY_TAG(TAG_Status_Stunned, "Status.Stunned"); UE_DEFINE_GAMEPLAY_TAG(TAG_Ability_Attack_Melee, "Ability.Attack.Melee"); UE_DEFINE_GAMEPLAY_TAG(TAG_Data_Damage, "Data.Damage");Data tables of tags, for large projects that generate them.
Avoid FGameplayTag::RequestGameplayTag(FName("Status.Stunned")) scattered through code: a typo is only caught at runtime. Native tags turn that into a compile error.
Using tags
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Tags")
FGameplayTagContainer OwnedTags; // designers pick tags from a tree picker
UPROPERTY(EditDefaultsOnly, Category = "Tags", meta = (Categories = "Damage.Type"))
FGameplayTag DamageType; // the picker only shows Damage.Type.*
void AArenaEnemy::ApplyHit(const FGameplayTag& HitType)
{
if (OwnedTags.HasTag(TAG_Status_Stunned)) return; // hierarchical match
if (HitType.MatchesTag(FGameplayTag::RequestGameplayTag(TEXT("Damage.Type.Fire"))))
{
OwnedTags.AddTag(FGameplayTag::RequestGameplayTag(TEXT("Status.Debuff.Burning")));
}
}| Call | True when |
|---|---|
TagA.MatchesTag(TagB) |
A is B or a child of B: Damage.Type.Fire matches Damage.Type |
TagA.MatchesTagExact(TagB) |
A is exactly B |
Container.HasTag(T) |
some tag in the container matches T hierarchically |
Container.HasTagExact(T) |
the container holds exactly T |
Container.HasAny(Other) / HasAll(Other) |
any / all of Other's tags are matched |
FGameplayTagQuery |
an expression: "all of {A, B} and none of {C}" |
Note the direction: a container holding Status.Debuff.Burning has Status.Debuff (asking about the parent matches), but a container holding only Status.Debuff does not have Status.Debuff.Burning.
Interfaces tie it together: implement IGameplayTagAssetInterface (GetOwnedGameplayTags) on actors so any system can query their tags without knowing their class. Actors with a GAS ability system component get this for free.
A runnable tag matcher
The model stores tags as strings and implements the matching rules above, including the parent expansion that makes HasTag hierarchical. The engine does the same work with precomputed parent lists so each check is fast.
#include <iostream>
#include <set>
#include <string>
#include <vector>
using Tag = std::string;
bool MatchesTag(const Tag& a, const Tag& b) { // a is b, or a child of b
return a == b || (a.size() > b.size() && a.compare(0, b.size(), b) == 0 && a[b.size()] == '.');
}
struct TagContainer {
std::set<Tag> Tags;
bool HasTag(const Tag& t) const { for (auto& x : Tags) if (MatchesTag(x, t)) return true; return false; }
bool HasTagExact(const Tag& t) const { return Tags.count(t) > 0; }
bool HasAny(const TagContainer& o) const { for (auto& t : o.Tags) if (HasTag(t)) return true; return false; }
bool HasAll(const TagContainer& o) const { for (auto& t : o.Tags) if (!HasTag(t)) return false; return true; }
};
// A tiny tag query: all of Required, none of Blocked.
bool Query(const TagContainer& c, const TagContainer& required, const TagContainer& blocked) {
return c.HasAll(required) && !c.HasAny(blocked);
}
int main() {
std::cout << std::boolalpha;
TagContainer enemy{{"Status.Debuff.Burning", "Team.Red", "Enemy.Type.Grunt"}};
std::cout << "HasTag(Status.Debuff) " << enemy.HasTag("Status.Debuff") << "\n";
std::cout << "HasTagExact(Status.Debuff) " << enemy.HasTagExact("Status.Debuff") << "\n";
std::cout << "HasTag(Status.Debuff.Burning.Hot) " << enemy.HasTag("Status.Debuff.Burning.Hot") << "\n";
std::cout << "HasTag(Status.Deb) " << enemy.HasTag("Status.Deb") << " (not a parent, just a prefix)\n";
TagContainer immune{{"Status.Immune", "Status.Debuff.Burning"}};
std::cout << "HasAny({Status.Immune, Status.Debuff.Burning}) " << enemy.HasAny(immune) << "\n";
// "Can this ability activate?" Required: Team.Red; Blocked: Status.Stunned, Status.Dead.
TagContainer req{{"Team.Red"}}, blocked{{"Status.Stunned", "Status.Dead"}};
std::vector<std::set<Tag>> states = {enemy.Tags, {"Team.Red", "Status.Stunned"}, {"Team.Blue"}};
for (auto& s : states) {
TagContainer c{s};
std::cout << "activate with {";
bool first = true;
for (auto& t : s) { std::cout << (first ? "" : ", ") << t; first = false; }
std::cout << "}: " << Query(c, req, blocked) << "\n";
}
}HasTag(Status.Debuff) true
HasTagExact(Status.Debuff) false
HasTag(Status.Debuff.Burning.Hot) false
HasTag(Status.Deb) false (not a parent, just a prefix)
HasAny({Status.Immune, Status.Debuff.Burning}) true
activate with {Enemy.Type.Grunt, Status.Debuff.Burning, Team.Red}: true
activate with {Status.Stunned, Team.Red}: false
activate with {Team.Blue}: false
The fourth line is why the engine compares tag nodes, not string prefixes: Status.Deb is not a tag at all, and even a real tag Status.Deb would not be a parent of Status.Debuff.
Tag naming that scales
- Root categories with clear meanings:
Ability.*,Status.*,Damage.Type.*,Event.*(gameplay events),Input.*,Cooldown.*,Data.*(SetByCaller keys),GameplayCue.*(cosmetic effects; GAS requires this root for cues). - Status tags describe state (
Status.Stunned), not causes (Status.HitByHammer). Effects can grant the same state for different reasons. - Renaming a tag in the manager adds a redirect in the ini, so saved assets keep working. Removing a tag that assets still reference leaves them with an invalid tag; check with the Search for References option first.
Test yourself
A container holds Damage.Type.Fire. What does HasTag(Damage.Type) return?
- true
- false
- It depends on the order
- A compile error
A container holds only Status.Debuff. What does HasTag(Status.Debuff.Burning) return?
- true
- false
- true if Burning is registered
- It throws
Why prefer UE_DEFINE_GAMEPLAY_TAG native tags over RequestGameplayTag("…") in code?
- They replicate faster
- A typo becomes a compile error instead of a runtime failure, and there is no lookup cost
- They are the only kind GAS accepts
- They can't be renamed