Unreal Blueprint callable functions in C++

Writing some C++ that can be called in Unreal is really easy and is something you’re going to want to do at some point if only for performance reasons.

Here’s the header from a test class:

class UHelpers : public UBlueprintFunctionLibrary

UFUNCTION(BlueprintCallable, Category = "Save Game")
static void LoadGame(const APlayerState* playerState, USaveGame* saveGameIn, USaveGame*& saveGameOut, bool& status);


This function takes an APlayerState and a USaveGame object and returns a USaveGame and a boolean. These are all shown as pins in the blueprint editor as you would expect.

This shows how to solve two of the not quite so obvious problems that you are going to have. The first is how to return more than one value from a function. A value can be returned from the function as with any C++ function, and Unreal
will create an output pin for it but any parameters that are passed by reference are considered to be output parameters by Unreal.

The second thing it shows is how to return a class as an output parameter. This is done by having a pointer to a reference for that class which is probably not obvious unless you’ve had a bit of experience with C++. In this particuar case I then just assign saveGameIn to saveGameOut at the end of the function so that the value can then
be chained into the next node of the graph. I’m not sure if you can define a function parameter to be both an input and an output pin, but if you can it’s not obvious as to how.

You can also add UPROPERTY(ref) before each parameter definition if you wish for it to be considered a reference in the blueprint editor. I’ve not experimented with any speed differences this may have.