Alrighty, I think I’ve created a decent solution to my initial post. The below code is a 1 time conversion from GameplayTagContainer into a Name Array that can easily and quickly be searched at any time.
It seems pretty good to me, but let me know if there’s actually any big flaws/performance problems with this method.
Here’s what I’m using for an Item Chest where developers can select multiple item tags to spawn in the chest.
UPROPERTY(EditAnywhere, meta = (Categories = "Items")) FGameplayTagContainer ItemTag;
TArray<FName> NTags;
BeginPlay(){
//Convert GameplayTagContainer into array of names
for (int8 i = 0; i < ItemTag.Num(); i++) {
FString tagStr = ItemTag.GetByIndex(i).GetTagName().ToString();
int8 endDot = tagStr.Find(".", ESearchCase::IgnoreCase, ESearchDir::FromEnd);
if(endDot > -1) tagStr = tagStr.RightChop(endDot+1);
NTags.Add(*tagStr);
}
}
That also puts only the last tag into the list, removing the categories. So:
Items.Potions.MediumPotion
Items.Potions.HighPotion
Items.Bombs.FireBomb
Becomes MediumPotion, HighPotion, FireBomb. Easy to loop through and spawn the items. Also easy to do the quick lookups I was asking about before using:
Tags.Contains("MediumPotion");
For single GameplayTags, you can also easily use the below method to check if it contains a specific tag:
GameplayTag.GetTagName().ToString().Contains("MediumPotion");
This method might be easier to search for single tags than requesting a fully typed out + categorized gameplay tag.
Whether it performs better or worse I don’t know, but might save typing-time in the long run for single lookups.