BP function tricks

So I recently discovered some very handy ways of expanding BP nodes. Turns out you can do a lot of things with a couple of meta specifiers:

 

 Multiple execution outputs:

Given an enum, we can decide to branch the node execution based on it. You run any logic you want, the output execution pin will be whatever value return has when the function ends.

.h

//Node branching result
UENUM(BlueprintType)
enum ENodeResult
{
	A,
	B,
	C
};

//Runs the given action and when it ends, branches the BP execution based on the result
UFUNCTION(BlueprintCallable, meta = ( ExpandEnumAsExecs = "result"))
	void Branching(ENodeResult input, TEnumAsByte& result);

.cpp
void ALatentExample::Branching(ENodeResult input, TEnumAsByte& result)
{
	result = input;
}

 

 

Hiding and assigning inputs:

You can hide inputs with the HidePin metadata specifier. (the doc says that only one pin per function can be hidden but it works with many, keep it in mind just in case).

You can as well use DefaultToSelf to assign the self value to an input by default. Very useful for WorldContextObject.

.h
//You can Hide pins and give them a self value
UFUNCTION(BlueprintCallable, meta = ( HidePin = "thisActor", DefaultToSelf = "thisActor"))
	virtual void DefaultToValue( AActor* thisActor);
        
   

Comments