To create a blueprint node with multiple exec pins in Unreal Engine, you can use the ExpandEnumAsExecs
meta
tag in the UFUNCTION
macro to specify the number of outputs
The ExpandEnumAsExecs
meta tag is a special meta tag that can be used in conjunction with an enum
parameter in a blueprint function to automatically generate multiple execution pins based on the number of enum values.
For example, let’s say we have the following enum:
UENUM(BlueprintType)
enum class EL0CastResult : uint8 { Succeed, Failed };
We can use the ExpandEnumAsExecs
meta tag in our blueprint function declaration to automatically generate two execution pins based on the two values of the enum:
UFUNCTION(BlueprintCallable, Category = "Cast To Player branched", meta = (ExpandEnumAsExecs = "OutputPins"))
static APlayerCharacterBase* K2_CastToPlayer(AActor* Actor, EL0CastResult& OutputPins);
In this case, the ExpandEnumAsExecs
meta tag tells the blueprint system to automatically generate two output execution pins based on the EL0CastResult
enum, one for the Succeed
value and one for the Failed
value.
Then you can set the value of the OutputPins
parameter in your function body to control the execution flow.
if (PlayerPawn)
{
// Exec pin 1
OutputPins = EL0CastResult::Succeed;
}
else
{
// Exec pin 2
OutputPins = EL0CastResult::Failed;
}
Full code
// hpp
UENUM(BlueprintType)
enum class EL0CastResult : uint8 { Succeed, Failed };
UCLASS()
class THEPATHTOL0_API UL0GameplayLibrary : public UBlueprintFunctionLibrary
{
UFUNCTION(BlueprintCallable, Category="Cast To Player branched", meta=(ExpandEnumAsExecs="OutputPins"))
static APlayerCharacterBase* K2_CastToPlayer(AActor* Actor, EL0CastResult& OutputPins);
}
// cpp
APlayerCharacterBase* UL0GameplayLibrary::K2_CastToPlayer(AActor* Actor, EL0CastResult& OutputPins)
{
APlayerCharacterBase* PlayerPawn = CastToPlayer(Actor);
if (PlayerPawn)
{
// Exec pin 1
OutputPins = EL0CastResult::Succeed;
}
else
{
// Exec pin 2
OutputPins = EL0CastResult::Failed;
}
return PlayerPawn;
}
Leave a Reply