How to get all tags with a matching part?

A UActorComponent has the following tags:

Role.Starter
Event.Alpha.Start
Event.Alpha.Finish
Event.Beta.Start
Timer.Start.Zero

The TArray ComponentTags contains all these.

How can we get all tags that match a prefix such as Event.Alpha (which should return Event.Alpha.Start and Event.Alpha.Finish) using C++?

How can we get all tags which contain an arbitrary part such as Start (which should return Event.Alpha.Start, Event.Beta.Start and Timer.Start.Zero but NOT Role.Starter)?

disabling bExactMatch should work for these

for this i think you’d have to convert a tag to string array and check contains “Start”

Is it possible to clarify this? I have an array of all tags and want an array of tags matching a requirement. Where is bExactMatch used?

you have to loop over the array and use MatchesTag which should expose a variable for ExactMatch and if MatchesTag add it to your OutArray.

PS you can use a GameplayTagContainer and break to an array. or see if the container itself has functions useful to you

These only work with gameplay tags. Component and actor tags are simple FName fields it seems. I was using AActor::GetComponentsByTag which works with the old tagging system, not the newer gameplay tags.

I was hoping there was an automatic way but it seems that it has to be done manually. The first thing that comes to mind is something like:

TArray<FName> MatchingTags = ComponentTags.Filter([](const FName& Tag){/*Code that returns true if desired substring exists*/});

Extending it to gameplay tags you can do something like:

TArray<FGameplayTag> MatchingTags = MyGameplayTagArray.Filter([](const FGameplayTag& Tag){return Tag.MatchesTag(TargetTag)});

Or when using FGameplayTagContainer:

// Create a container of looked-for tags
FGameplayTagContainer FilterContainer = ...

FGameplayTagContainer MatchingTags = MyGameplayTagContainer.Filter(FilterContainer);

ah sorry didnt realize you were using the old system, yeah you can convert them but probably easier to use an interface to GetGameplayTags or something.

otherwise you convert the FName to String and then do something like

FString TagString = MyTag.ToString();

TArray<FString> Tags;
TagString.ParseIntoArray(Tags, TEXT(“.”), true);

1 Like