How to Get Native Gameplay Tags in Blueprints in Unreal

Gameplay Tags in Unreal Engine are a powerful tool for hierarchical labeling of objects. You can use them to denote damage types, faction alignments, and any other kind of distinguishing label you can imagine, with a great degree of flexibility. You can read all the details in the Unreal documentation here, but the main point of Gameplay Tags is to allow you to make qualitative determinations about the types or relationships of a particular object, in order to decide what to do with it.

For example, you might have special rules for processing different types of damage to an enemy or player based on weaknesses: an attack that does Damage.Fire type might deal extra damage against an enemy that has an ice affinity. You could distinguish it further with another tier, e.g. Damage.Elemental.Fire vs. something like Damage.Physical.Piercing. And due to the hierarchical nature, you could represent a query for all elemental damage types as just Damage.Elemental, and anything underneath would match that.

This is all wonderful, but if you are working on a Blueprint project, there is a slight problem. Take a look at this function call that checks for a matching Gameplay Tag:

1-2.png

This and numerous other functions are provided for developers to check assigned Gameplay Tags on an object; however, if you have ever tried to use them in an all-blueprint project, you probably came to realize that, well, they don’t seem to work! Or more precisely, they don’t work on any of the blueprints you have. And the reason for that probably won’t surprise you: the base classes for blueprints don’t implement the required interface, IGameplayTagAssetInterface, which is necessary to call these functions.

So what can you do about this?

Well, you could implement your own such interface in blueprint, with a function like GetGameplayTags, and also write your own library functions to support all the same things as the built-in nodes.

Or, with a little C++ finagling, you can have native, in-editor support for Gameplay Tags on whatever blueprints you want!

Note: You will need to have Visual Studio installed to do this, along with the C++ game dev and Unreal Engine packages. For info on how to do that, check out this article.

Creating the base class

First, you need to create a new C++ class to use as a base. In my case, I have already done this for Actor, but I need to do it again for Pawn, so I create a Pawn_GT class with Pawn as its parent:

1-1.png

Once this is finished, you can see the newly created source files under the Source directory, and you should also have a .sln solution file that you can open with Visual Studio.

The first file we’re interested in is Pawn_GT.h. Here is what it needs to look like, at a minimum:

The key changes we’re making are on lines 21-22, where we add a container for the gameplay tags as a property, and line 31 where we implement the function to provide that tag container when the interface is called. This is what we have to do to to allow the functions for Gameplay Tag Asset Interface to be callable on our objects.

The other thing we need to do to finish this is add the Gameplay Tags module as a dependency in the project’s .Build.cs file:

The only changes we have to make here are on lines 9 and 11, where we add ”GameplayTags” to these arrays. This tells Unreal to include the necessary modules in the editor to make this work properly.

And now we’re good to go! Any blueprint that is a child of this custom class will have a Gameplay Tags container property that lets us set the tags we want, and query them to our hearts’ content.