From string To Gameplay Tag?

Ill be quick and to the point. There is no way in blueprint to have a string of a gameplay tag and drag out from the string to ‘get’ a tag by that name from the main list of tags (from project settings tag list).

Does anybody know how to accomplish this? Would be nice to just call a new node that has an input for string and outputs a tag struct and bool for if found or not. behind the scenes of it (c++) its just searching for a matching gameplay tag based on that input string, from the project setting existing tags, not a container.

Its odd that you can convert a tag name to string but not a string to tag.

Im not versed in C++ so its not something i know how to create.

First, it’s called “request gameplay tag”:"
upd: oops, it was a custom function and i missed this fact during initial answer

Second, I use this function alot from c++, but never used it in blueprints as there you can define the tags directly. So i suggest you to doublecheck whether you really need it.

1 Like

This is not popping up for me at all. Is that your own custom node that was made in C++?

I save a gameplay tag to my item database. On recreation its a string from the database that needs to be recreated as a tag but there currently isnt a way to do that. I had to create a datatable with the structure of a tag just so i could get a matching name and get that rows tag. Not very versatile since it requires me to make sure its always updated with any new tags ive added.

if you use Make Literal Gameplay Tag you can just choose which tag you want and it returns an FGameplayTag that you can use for queries. There’s also a Make Literal Gameplay Tag Container which does the same but for a container. Hope this helps!

Make Literal Gameplay Tag | Unreal Engine Documentation

Unfortunately neither of those 2 can turn a string and match it to a tag and output it.

@IrSoil was that a C++ function you made?

Oops, you right. It was just so basic and simple that i missed it was a custom function, sorry about that. C++'s equivalents would be the

FGameplayTag::RequestGameplayTag("My.String.Tag");

or

bool UMyBlueprintLibrary::TryRequestGameplayTag(FName TagName, FGameplayTag& Tag)
{
	Tag = UGameplayTagsManager::Get().RequestGameplayTag(TagName, false);
	return Tag.IsValid();
}

Any of them you can expose to blueprints with header like:

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "GameplayTagContainer.h"
#include "%InsertYourCurrentFileNameHere%.generated.h"

UCLASS()
class DONT_FORGET_TO_CHANGE_THIS_API_MACRO_TO_YOURs_ONE_API UMyBlueprintLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintPure, Category = "GameplayTags")
	static bool TryRequestGameplayTag(FName TagName, FGameplayTag& Tag);
}
7 Likes

Thanks a lot! I dabbled in random bits of code i could scour from the internet earlier today but had no luck, especially since i didnt know what it was supposed to look like, what was missing, what was right and wrong, etc haha.

I’ll mess around with this new code you pasted and see what i get!

Hmm, cant seem to get it to build in order to test. I’m seriously shooting in the dark though on where i place what snippet of code lol. I’m VERY inexperienced with the .h and .ccp files in visual studio.

At this point it would been hard to describe it in details. In short this code can be put literally anywhere, as long as you keep required parts intact and properly replace the other parts.

You can try to check something like this to get initial understanding

you were missing a ; at the end :stuck_out_tongue:

Moving forward but new error popped up, but this time for the cpp.

1>D:\MMO_Project_5.1\MMO_BMonline\Source\MMO\Private\MyBlueprintFunctionLibrary.cpp(9): error C2027: use of undefined type ‘UGameplayTagsManager’
1>D:\UnrealEngine-5.1.0-release\Engine\Source\Runtime\GameplayTags\Classes\GameplayTagContainer.h(212): note: see declaration of ‘UGameplayTagsManager’
1>D:\MMO_Project_5.1\MMO_BMonline\Source\MMO\Private\MyBlueprintFunctionLibrary.cpp(9): error C3861: ‘Get’: identifier not found

i think maybe im missing an include type of some sort of tag manager?

For such error, the first thing to check, is to google undefined type like ue5 UGameplayTagsManager and find doc about it: UGameplayTagsManager | Unreal Engine Documentation

Here you can see, that the required header is
#include "GameplayTagsManager.h"
which we probably missed.

Also probably you missing a module GameplayTags in your *.build.cs file. Add it to PublicDependecyModuleNames, so this part of file would look similar to this:

 PublicDependencyModuleNames.AddRange(new string[] 
 {
     "Core",
     "CoreUObject",
     "Engine",
     "GameplayTags",
});

And then try compile project again

1 Like

Yep adding the “GameplayTags”, to my publicdependency + the include of gameplay in the cpp did the trick! It compiled and is firing up!

edit: Fired up and called the node! Am about to give it a test to see if it works as intended! Thanks a lot!!

Thank you so much! Printing to screen is working correctly! Very much appreciated!! You’ve done me a great service!

Heavy issue for Python scripting is to convert string to gameplay tag, at least in 5.1. Need a custom C++ blueprint library for that.

.build.cs:

Add to PublicDependencyModuleNames:

"Engine",
"GameplayTags",
"UnrealEd",
"PythonScriptPlugin"

Now a blueprint library:

ECRPythonHelpersLibrary.h:

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "GameplayTagContainer.h"

#include "ECRPythonHelpersLibrary.generated.h"

UCLASS()
class ECREDITORMODIFICATIONS_API UECRPythonHelpersLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintCallable, Category = "GameplayTags", meta = (ScriptMethod))
	static FGameplayTag ConvertStringToGameplayTag(const FString& TagName);
};

.cpp:

#include "ECRPythonHelpersLibrary.h"

FGameplayTag UECRPythonHelpersLibrary::ConvertStringToGameplayTag(const FString& TagName)
{
	// Get the GameplayTagsManager instance
	FGameplayTag Tag = FGameplayTag::RequestGameplayTag(FName(*TagName));

	// Optional: Check if the tag exists
	if (!Tag.IsValid())
	{
		UE_LOG(LogTemp, Warning, TEXT("Invalid GameplayTag: %s"), *TagName);
	}

	return Tag;
}

Then, in Python (after adding tag records to Config/DefaultGameplayTags.ini, it won’t work with not yet existing tags):
gameplay_tag = unreal.ECRPythonHelpersLibrary.convert_string_to_gameplay_tag(tag_str)

Also, if adding tag to container, don’t forget it’s not inplace operation, you want to assign result to variable:
container = unreal.GameplayTagLibrary.add_gameplay_tag(container, tag)

Epic Games, I hate you…

2 Likes