How to create an automatic cast/conversion node for custom data types using blueprint libraries in c++

Hi everyone!

I’ve always been a huge fan of writing clean blueprint code (and making c++ code that enables that. I just figured out how to create functions that can automatically convert a custom data type (struct) into some other data format.

Here is how it works:

You make your custom struct with some data

USTRUCT(BlueprintType)
struct FMyPrintableStruct
{
	GENERATED_BODY()

	UPROPERTY(BlueprintReadOnly)
	int32 FirstValue;

	UPROPERTY(BlueprintReadOnly)
	FString MyStringThatILike;
};

Then you create the blueprint function library with the conversion code

//.h
UCLASS()
class UMyAwesomeFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintPure,meta = (DisplayName = "Convert To String",CompactNodeTitle = "->",BlueprintAutocast),Category = MyPrintableStruct)
	static FString Conv_MyPrintableStructToString(MyPrintableStruct);
};

//.cpp
FString UMyAwesomeFunctionLibrary::Conv_MyPrintableStuctToString(MyCustomStruct Struct)
{
	return  Struct.MyStringThatILike + " - " + FString::FromInt(Struct.FirstValue);
}

And that’s it!

Here is a tutorial to show how I did it