Daily Unreal Column #24 - Native Gameplay Tags
Are you tired fetching gameplay tags references using FGameplayTag::RequestGameplayTag function? Today you will learn how to define gameplay tags directly in the code.
For a while now Unreal Engine code has two helper macros for declaring and defining gameplay tags natively.
To declare a gameplay tag, use the UE_DECLARE_GAMEPLAY_TAG_EXTERN
macro in a header file. For example:
UE_DECLARE_GAMEPLAY_TAG_EXTERN(State_Walking);
UE_DECLARE_GAMEPLAY_TAG_EXTERN(State_Flying);
To define the above tags, use the UE_DEFINE_GAMEPLAY_TAG
macro in a source file. For example:
UE_DEFINE_GAMEPLAY_TAG(State_Walking, "State.Walking");
UE_DEFINE_GAMEPLAY_TAG(State_Flying, "State.Flying");
You can then access the gameplay tag anywhere in your code by simply calling State_Walking
or State_Flying
.
I recommend wrapping your gameplay tags declarations and definitions in a namespace to avoid any name conflicts.