Using GameplayTags

gameplaytageditor

I wasn’t able to find any tutorial or documentation about GameplayTags so I decided to create one myself. In this tutorial you will learn about:

  • Actor / Component Tag system,
  • UE4 introduced GameplayTag system
  • How to use them,
  • Why you should use them?

Why use Tags?

You can do a lot with tags, really a lot. For example:

  • Check if someone is friend or not with more complicated things like family or guild,
  • Check if enemy can be damaged by fire damage or any kind of damage,
  • Make points of interest and tag them for type without need to create new blueprint,
  • You can find specific actors/components based on tags,
  • Weapons can have different attributes as tags.
  • And basically what your imagination can do with tags.

Basically tags are used to filter some data in games, but you can do lot more with them.  The main different is that actor can have multiple tags, doing the same with ENUMS is doable but won’t be user-friendly.

Another thing is that you don’t need to cast for specific actor. For example you want to find all enemies that can be damaged by fire damage with some radius. You can just check their (Actors) tags without casting.  Or you want to check if actor have inventory. Just find component by tag – if it’s there it means that this actor have inventory. Simple as that.

Difference between Tag and GameplayTag

UE4 have two Tag systems: Actor/Component Tag and GameplayTags. The first one is known from UE3 and it doesn’t support categories or editor out of the box. GameplayTags in the other hand is new system that isn’t enabled by default but it’s working. It supports categories have editor and comes with more functionalities out of the box.

Using Tags

Using Tags is simple. Just open your Actor or Component and in Class Defaults you can add tags:

actortag

Actor Tags

componenttag

Component Tags

As you can see it’s just array with names.

After adding tags you can use a couple of nodes to find needed tags:

tagsblueprints

Using GameplayTags

To use GameplayTags you need to open your DefaultEngine.ini and add these:

[GameplayTags]
ImportTagsFromConfig=true

Then after opening editor again you can go to Project Settings -> Gameplay Tags:

gameplaytags

Currently it’s only visible as array – without GameplayTag editor (which you will see later in this tutorial) but I think Epic will add editor here as well.

From AnswerHub: Basically GameplayTags can be stored in categories:
Tags themselves are very generic and can be used for a lot of different things. The basic idea is that they are strings with a hierarchical relationship. E.g., they can have a parent. An example tag would be “A.B.C” or “Damage.Physical.Pierce”. That is really all tags are themselves. They hold no other data on their own.

GameplayTags can be used only in C++ for now. Your class need to implement interface and have special variable. Then you can add tags in editor – no coding is required.

It’s really simple.

Add new Actor C++ class using “New C++ Class…” option.  Then close editor.

Modify Build.cs file

To use GameplayTags you need to add module into your ProjectName.Build.cs file which is located in /Source folder.

Add “GameplayTags” into PublicDependencyModuleNames:

Adding GameplayTag Interface

Next step is to add gameplay tag interface. Your actor need to implement IGameplayTagAssetInterface.

As you can see my class is extending ACharacter and IGameplayTagAssetInterface. Thanks to that I’m able to use function to get my tags variable.

Creating GameplayTag variable

GameplayTags are stored in FGameplayTagContainer. You just need to create variable from this struct:

And now you need to use interface method to return this variable:

Thanks to this GameplayTag system will be aware of tags stored in this Actor.

Here’s full .h source for this Actor:

Adding GameplayTags.

Compile and open Editor.  Create Blueprint extending from your c++ class and open it.

Make sure you click on show inherited variables button:

show-inherited

Now you can see GameplayTags category and GameplayTags variable! If you click Edit GameplayTag editor will be opened.

gameplaytageditor

Those are from Project Settings -> Gameplay Tags. You can add tags from here as well – they will be added to global gameplay tags. That’s really cool and simple to use.

GameplayTags have more functionality than Actor/Compnent Tags:

gameplaytagsnodes

And they are much easier and faster to work with.

3 thoughts on “Using GameplayTags

  1. Hello,
    Thanks for your tutorial , I want to ask please create an example for calling a function in C++ and pass some Gameplay Tags from C++ into that function not from BP.
    Thanks

Leave a Reply to Vahid Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.