How can I create a blueprint node in C++ that has multiple exec output pins, like the Branch node or the Cast To ones.
I used the Sequence node in Utilies->Flow Control and you can keep adding pins. It will execute the first, then the second, then the third. This is really useful for setting up complicated gameplay where you need to branch your blueprint to a bunch of different areas.
It’s even easier if the order doesn’t matter, it’ll just do all of it (still technically in order but it won’t matter).
I am also interested in a real answer to this question, If it is possible or not via the UFUNCTION macro.
Looking into how the Branch and Sequences are created seem to use CreatePin() but finding out how to do this out side this namespace is driving me nuts
Also bumping this, there must be a way!
I’m specifically wanting to implement a “branch on clamp” node, with three outputs for a) the input value being between A & B; b) the input value is above B; c) the input value is below B.
I know I could do it with a couple of branches and comparitors, but I plan to use it a lot, so a single node would be great.
Thanks this seems to be the immediate solution of course but as stated above would be cool if this could be added as a potential feature. It seems the functionality is there in the engine, so technically it isn’t impossible, just not through the use of the UFUNCTION macro. If i figure it out I will be sure to post it.
I’d like to have Exec pins for OnSuccess and OnFailure for an HTTP call like when using the session nodes.
I found https://docs.unrealengine.com/latest/INT/API/Editor/BlueprintGraph/UK2Node_ExecutionSequence/AddPinToExecutionNode/index.html but this requires your node to be its own class as far as i understand. So you could make your function a class that is a child of UK2Node_ExecutionSequence but i don’t believe thats recommendable.
We have to hope that Epic makes this into a nice and easy to use macro. As far as i can tell Frozenfire has provided the best workaround.
You can do this. First, declare a new UEnum type:
UENUM(BlueprintType)
enum class EMyEnum : uint8
{
BranchA,
BranchB
};
Then, declare some Blueprint-exposed UFunction like this in your .h (change the parameters for whatever you need):
UFUNCTION(BlueprintCallable, Category = "Stuff", Meta = (ExpandEnumAsExecs = "Branches"))
void DoSomeBranch(int32 SomeInput, TEnumAsByte<EMyEnum>& Branches)
And in your .cpp:
void AMyClass::DoSomeBranch(int32 SomeInput, TEnumAsByte<EMyEnum>& Branches)
{
if (SomeInput == 1)
{
Branches = EMyEnum::BranchA;
}
else
{
Branches = EMyEnum::BranchB;
}
}
Then you should be able to use it like this in your Blueprint:
Thanks for that, really useful
Oh didnt know about this one
You can also create custom node by exteding UK2Node class, it let you do anything with pins and apperence of node. Thing is theres no documentation on it and you need to figure this yourself, its complex but always a option. All nodes are made like that (in fact funtion bind node is K2Node_CallFuntion), you can find code of them here:
Worked like a charm. Only had to change “enum class EMyEnum : uint8” to “enum EMyEnum” since it caused an error when casting from uint8 to TEnumAsByte
I get generated error in the compiler about TEnumAsByte failing to with EMyEnum and MarcAndreG solution get another error about missing {
Hm, I was thinking about doing this for my project, but I think, that I should do this after the blueprints are compiled into C++ Code and after Blueprints are stored as textfiles
Actually, the form with : uint8 is the new and better one. This way you can convert any enum to an integral type using C-style cast like (int32)EMyEnum::BranchA.
You can remove the cast with TEnumAsByte and simply use the enum type name. Like so:
// .h
UENUM(BlueprintType)
enum class EMyEnum : uint8
{
BranchA,
BranchB
};
UFUNCTION(BlueprintCallable, Category = "Stuff", Meta = (ExpandEnumAsExecs = "Branches"))
void DoSomeBranch(int32 SomeInput, EMyEnum& Branches)
// .cpp
void AMyClass::DoSomeBranch(int32 SomeInput, EMyEnum& Branches)
{
if (SomeInput == 1)
{
Branches = EMyEnum::BranchA;
}
else
{
Branches = EMyEnum::BranchB;
}
}
I got errors with the early method. This solution instead worked fine!
If can help, i just used it in a public class with static methods(a function library).
Actually, AddPinToExecutionNode is called by SGraphNodeK2Sequence.
There are two ways for you to get a similar behavior : extending SGraphNode_K2Sequence or implementing CreateVisualWidget.
You have to create your own implementation of SGraphNode (there is no need to implement SGraphNodeK2Base) - copy code from SGraphNodeK2Sequence.
But I can’t find a way to implement the “remove pin” button. This has something to do with FUICommandList and FGraphEditorCommands::Get().RemoveExecutionPin, but I don’t now how to handle this stuff. If someone could help me ?
Also, blueprints don’t show the name of exec pins named “Then”
Which is also true for pins from Blueprint created Functions and Macros by the way.
In-Exec pins named “Execute” also won’t show the name.
@Evigmae haven’t tested, but wouldn’t this do the trick?
UENUM(BlueprintType)
enum class EMyEnum : uint8
{
Then UMETA(DisplayName = "Then"),
Success UMETA(DisplayName = "On Success"),
Fail UMETA(DisplayName = "On Failure")
};
you rock!!