How do you get an line trace hit actor's Gameplay Tags

I am simply looking for the way to check if an actor pinged by a line trace is assigned a certain Gameplay tag.

the tag is defined like this:

//in .h
UE_DECLARE_GAMEPLAY_TAG_EXTERN(WallRunWallTag);

// in .cpp
UE_DEFINE_GAMEPLAY_TAG_COMMENT(WallRunWallTag, "Interactable.WalRunWall", "This Object Is A Wallrun Wall");

As I understand this means a FGameplayTagContainer assigned WallRunWallTag will be assigned tags Interactable and WallRunWall
I want to check if an Actor from a line trace is assigned the WallRunWall tag, However I am unaware of how to access an object’s FGameplayTagContainer in order to call .HasTag, or to check if the object even has a FGameplayTagContainer at all?

Edit:
Tag is asigned to my “WallRunWall” class like this, all I did was this:

// in .h
FGameplayTagContainer WallRunWallTags;

//in .cpp
WallRunWallTags.AddTag(WallRunWallTag);

This is not answering your question directly but maybe the good old FName tags can be used here.
Hit.GetActor()->ActorHasTag(TEXT("WallRunning"));

You can also use an interface and return the gameplay tag.

Thank you, this worked, but is there any draw back to using the old tag system over the new gameplay tag system?

The old tags are just raw strings with no additional checks or “type safety”. So you can easily create bug or other undesired behavior by simply having a typo or a mismatch in what tag is applied to the actor and what tag you are looking for. Gameplay tags are sort of similar but since you typically declare them in the editor and also reference the tags you are looking for there, the editor can make sure that you are using the same valid “strings”. Also, gameplay tags are hierarchical, which has its uses in more complex scenarios. Unless you are quickly prototyping something that you will rewrite later, you should always use gameplay tags.

To answer your original question, you need to downcast the actor hit by the line trace to the type which has your gameplay tag container property. Then you somehow obtain this collection and query whether it has the said gameplay tag. Alternatively you could attempt to cast the actor to an interface that declares a function which the actor implements with this logic and call that. That should be a slightly cleaner approach if you want it to be fancier.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.