Native Gameplay Tags (New in 4.27 and UE5)

This is a quick run down on the new NativeGameplayTags which was added to UE4.27 and UE5. These tags will populate the Editor GameplayTags drop down also (same as my struct version). Though you can also add these tags to your DefaultGameplayTags.ini just fine, as the engine will not allow dupes!

This class adds the following macros:

/**
 * Declares a native gameplay tag that is defined in a cpp with UE_DEFINE_GAMEPLAY_TAG to allow other modules or code to use the created tag variable.
 */
#define UE_DECLARE_GAMEPLAY_TAG_EXTERN(TagName)

/**
 * Defines a native gameplay tag that is externally declared in a header to allow other modules or code to use the created tag variable. (4.27 and 5.0 only)
 */
#define UE_DEFINE_GAMEPLAY_TAG(TagName, Tag) (4.27 and 5.0 only)

/**
 * Defines a native gameplay tag with a comment that is externally declared in a header to allow other modules or code to use the created tag variable. 5.1+ only
 */
#define UE_DEFINE_GAMEPLAY_TAG_COMMENT(TagName, Tag, Comment) (5.1+ only)

/**
 * Defines a native gameplay tag such that it's only available to the cpp file you define it in.
 */
#define UE_DEFINE_GAMEPLAY_TAG_STATIC(TagName, Tag)

We will start with the simplest one, UE_DEFINE_GAMEPLAY_TAG_STATIC. This is only used in your .cpp files, and allows usage of that tag only in that file. Useful for a quick one off tag. I do recommend wrapping them in a namespace to avoid global pollutions. Example here:


namespace KaosGameplayAbilityTags 
{
	UE_DEFINE_GAMEPLAY_TAG_STATIC(TAG_Gameplay_Action_Player_AimDownsights, "Gameplay.Ability.AimDownSights");
	UE_DEFINE_GAMEPLAY_TAG_STATIC(TAG_Gameplay_Status_AimingDownSights, "Gameplay.Status.AimingDownSights");
}

UKaosGameplayAbility_ADS::UKaosGameplayAbility_ADS()
{
	NetExecutionPolicy = EGameplayAbilityNetExecutionPolicy::LocalPredicted;
	NetSecurityPolicy = EGameplayAbilityNetSecurityPolicy::ClientOrServer;
	ActivationOwnedTags.AddTagFast(KaosGameplayAbilityTags::::TAG_Gameplay_Status_AimingDownSights);
	AbilityTags.AddTagFast(KaosGameplayAbilityTags::TAG_Gameplay_Action_Player_AimDownsights);
}

As you can see, we define these tags, and use the Name to use them. Benefit to this is we can use these in the constructor!

The other two macros need to work in tandem, and they can be used in a header file for example, “MyGameplayTags.h”
with an example below:

// Copyright InterKaos Games. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"

namespace MyGamesTags
{
	UE_DECLARE_GAMEPLAY_TAG_EXTERN(TAG_Gameplay_Status_Dead);
	UE_DECLARE_GAMEPLAY_TAG_EXTERN(TAG_AbilityActivation_Fail_Dead);
}

with the corresponding line in the cpp file:

(UE 4.27 and 5.0)

// Copyright InterKaos Games. All Rights Reserved.

#include "KaosNativeTags.h"

namespace MyGamesTags
{
	UE_DEFINE_GAMEPLAY_TAG(TAG_Gameplay_Status_Dead, "Gameplay.Status.Dead")
	UE_DEFINE_GAMEPLAY_TAG(TAG_AbilityActivation_Fail_Dead, "AbilityActivation.Fail.Dead")
}

(UE 5.1+)

// Copyright InterKaos Games. All Rights Reserved.

#include "KaosNativeTags.h"

namespace MyGamesTags
{
	UE_DEFINE_GAMEPLAY_TAG_COMMENT(TAG_Gameplay_Status_Dead, "Gameplay.Status.Dead", "Tag applied to actor when they are dead")
	UE_DEFINE_GAMEPLAY_TAG_COMMENT(TAG_AbilityActivation_Fail_Dead, "AbilityActivation.Fail.Dead", "Ability failed to activate cause the AvatarActor was dead.")
}

We can then include the header file “KaosNativeTags.h” in any .cpp file, and use the corresponding tag

			if (OptionalRelevantTags && AbilitySystemComponentTags.HasTag(MyGamesTags::TAG_Gameplay_Status_Dead))
			{
				// If player is dead and was rejected due to blocking tags, give that feedback
				OptionalRelevantTags->AddTag(MyGamesTags::TAG_AbilityActivation_Fail_Dead);
			}

Since UE 5.1 there is now a way to comment tags. Before this you had no way to add comments to native tags.

One more thing of note, sometimes packaging issues can happen, and this can be solved by shadowing the tag inside DefaultGameplayTags.ini.

With that, hopefully you can make use of these in your game code!