Download

Confused about gameplay tags; Adding/removing tags from another actor.

I have an actor component that I want to modify the tags of its owner, I thought this would be as easy as simply getting a reference to the owner and then getting a reference to the Gameplay Tag Container, but this doesn’t seem to work. From what I can tell it seems to be impossible to get a reference to a Gameplay Tag Container in blueprint. There isn’t even a variable type for a reference.

I thought perhaps my issue was that I hadn’t implemented the IGameplayTagAssetInterface in C++. So I did that, but I still see no way to access the tag container from outside of the actor. Get Owned Tags doesn’t seem to return a reference.

So what is the expected approach to actor add a gameplay tag to a different actor? In my working code above, I’m casting to a parent class that has the container variable so I can access it directly.

Is this the way the system is expected to be used? With all taggable actors inheriting from a parent class containing the variable then casting to it to modify the tags? (or implementing an interface + logic for handling the adding/removing of tags?)

I guess my post was rather vague so here’s an attempt to illustrate a particular problem with the above casting setup; I want my actor component to work on characters, pawns, and regular actors. Assuming I set up custom parent classes for all of them, I end up having to do cast checks like this every time I want to add or remove a tag:

An alternative to this would be to use an interface and putting the add/remove code inside the parent classes. This seems like an improvement over the above approach but it still means having duplicate code in 3 different classes. It also means I have two different interfaces, the C++ one that comes with gameplay tags, and the BP interface I have to create to expand it.

I feel like there’s gotta be a better way to do this, and I would really like to know what it is.

At this point I get the sense that the ideal solution would be to just expand the engines C++ Actor class, since pawn and character both inherit from it. But I am really not confident doing that…

Still looking for a better approach to this if anyone has one

This is unfortunately not an answer, just going to point to this other post that you can read to maybe understand what is going on with that? Though I must admit, it’s not making me understand why it’s not exposed to blueprint. You have pretty much realized the options you have. Well, instead of modifying the native actor, you could make a child class and override the interface. More information in the post.
https://forums.unrealengine.com/unre…-to-blueprints

Do you mean create a child interface that inherits from the IGameplayTagsAssetInterface and put my add/remove functions in there? Or make my own C++ Interface?

I’ve already done what that thread is mainly taking issue with; I’ve implemented the interface into parent C++ classes that my actors all inherit from. Unfortunately the problem is that it has no functions for adding/removing tags. It only does queries (and none return a reference). Short of replacing it (or augmenting it) with my own interface I’m not sure how to fix that.

I did think of another option though which resolves my duplicate code issue: Put the tag container in its own actor component rather than on the actor itself. This comes with the annoyance of having to find the component every time I want to add/remove a tag, I don’t know what the performance implications of that are. But it does avoid having to duplicate code in different classes or having to chain together a bunch of casts.