Introduction

You all know the automatic conversion system available in Unreal’s blueprints (when you drag and drop a pin of one type on a pin of another type). This is a very handy feature to save time during blueprint development. Basic types already have automatic converters, such as Integer to String, Float to Integer, Name to String and so on…

In this post, we’ll see how to create our own automatic converters for your custom types.

Let’s say we have a UMetaLandscape blueprint type, which is a composition of the ALandscape type. We want to create a custom automatic converter to drag and drop an ALandscape pin on an UMetaLandscape pin.

Our converters

Existing converters can be found in Kismet libraries classes: UKismetStringLibrary, for instance, contains all strings converters such as RotatorToString, ColorToString and so on…

There are few conventions when we want to create our own automatic type converter function:

  • It must take the wished type to convert as input parameter.
  • It must return the wished output type as return type.
  • The function must be exactly named this way: Conv_{FromType}To{ToType} without A,U,F,… prefixes (Conv_TestToString for instance) .
  • It must be a static function.
  • The function’s class must be a blueprint function library (UBlueprintFunctionLibrary)
  • The function must be an UFUNCTION BlueprintPure.
  • The UFUNCTION must have the meta tag BlueprintAutocast.

 

ALandscape to UMetaLandscape converter example

 

Header file content:

/**
* Function to auto-convert landscape to meta landscapes
* @param Landscape the landscape
* @return the meta landscape
*/
UFUNCTION(BlueprintPure, meta = (DisplayName = "Landscape To Meta Landscape", CompactNodeTitle = "->", BlueprintAutocast), Category = "ProceduralGeneration|MetaLandscape")
static UMetaLandscape* Conv_LandscapeToMetaLandscape(ALandscape* Landscape);

 

Cpp file content:

UMetaLandscape* ULandscapeGeneratorLibrary::Conv_LandscapeToMetaLandscape(ALandscape* Landscape)
{
	return UMetaLandscape::FromLandscape(Landscape);
}

 

Please note the usage of UFUNCTION’s meta tag CompactNodeTitle to allow this node to be compact and have the same design as IntegerToString converter.

Once compiled, we have a new message during drag and drop:

 

And once click released, our converter is automatically created.

 

And voilà! Our custom converter works perfectly and will help us to save a lot of time!

Enjoy.