Context.

If you used to create some custom blueprint nodes (using blueprint function library or directly into a UCLASS), you probably know the different ways to pass parameters to this function with their pros and their cons.

Let’s summarize.

When we want to use a UCLASS as a parameter, we need to pass it by address, otherwise we will have a compiler error:

Missing '*' in Expected a pointer type

But, we have two ways to do the job (in the following example, UGenerationModule is a UCLASS):

1. Pointer by copy
UFUNCTION(BlueprintCallable, DisplayName = "Add", Category = "ProceduralGeneration|Noises")
static UGenerationModule* ConstructAdd(UGenerationModule* ModuleA, UGenerationModule* ModuleB);

2. Pointer by ref
UFUNCTION(BlueprintCallable, DisplayName = "Add", Category = "ProceduralGeneration|Noises")
static UGenerationModule* ConstructAdd(UGenerationModule*& ModuleA, UGenerationModule*& ModuleB);

 

On the first hand, if we pass our UCLASS pointer by copy, it works perfectly, but the input pin isn’t compulsory… Indeed, if we want to compile the blueprint without linking the pin, we can.

This is a major issue in our case, let’s say we want the ModuleA and MobuleB variables to be always filled and avoid nullptr, we need to check if the pointers are not null in the function and so on… That’s too much work and checks for an easy task.

On the other hand, if we pass our UCLASS pointer by ref, we need to specify this ref as const, otherwise the refs will be interpreted as output pins… That’s not what we want, and we don’t want to use const in our case.

Solution.

So, we want our UCLASS as an input parameter without the const keyword.

The only way is to use the specific UE macro: UPARAM(ref).

Usage:

UFUNCTION(BlueprintCallable, DisplayName = "Add", Category = "ProceduralGeneration|Noises")
static UGenerationModule* ConstructAdd(UPARAM(ref) UGenerationModule*& ModuleA, UPARAM(ref) UGenerationModule*& ModuleB);

 

This way, the references are used as input pins and are compulsory, they must be linked to allow the blueprint to be compiled.