Custom nodes (C++)

Hey! I don’t know but my code doesn’t work for some reason, I’ve tried so many different things and gave up.
Any help you be awsome :slight_smile:
thanks in advance :slight_smile:

header file:

#pragma once

#include "GameFramework/Actor.h"
#include "multiRun.generated.h"
#include "EMultiRunEnum.h"

UCLASS(meta = (BlueprintSpawnableComponent))
class UNKNOWN_API AmultiRun : public ActorComponent
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintPure, Meta = (FriendlyName = "MultiRun", CompactNodeTitle = "MultiRun", Keywords = "Multi Run", ExpandEnumAsExecs = "Branches"), Category = Game)
		bool MultiRun(bool active, TEnumAsByte<EMultiRunEnum>& Branches);
};

cpp file:

#include "unknown.h"
#include "multiRun.h"
#include "EMultiRunEnum.h"


void multiRun::MultiRun(bool active, TEnumAsByte<EMultiRunEnum>& Branches)
{
	if (active)
	{
		Branches = EMultiRunEnum::BranchA;
		Branches = EMultiRunEnum::BranchB;
	}
}

Change BlueprintPure to BlueprintCallable. BlueprintPure is only for marking functions so that they appear to not need an exec pin when used in Blueprint.

They are analogous to ‘const’ functions in C++, but sometimes you actually need to do something non-const in your C++ code even though you want it to appear as a const function in Blueprint. In that case you would use BlueprintPure. But since your Blueprint function is specifically not const function (in fact, it exists only to modify control flow), you need to use BlueprintCallable, otherwise weird things will happen, such as a Blueprint compiler/intepreter discarding your function usage in the Blueprint graph.

Still didn’t work sorry, for some reason UE4 does not like my nodes so… yea idk what to do at this point…
I modified the code because it looked like it was conflicting with a different node but… nothing happened :frowning:
Header:

    #pragma once
    #include "GameFramework/Actor.h"
    #include "multiBranch.generated.h"
    #include "EMultiBranchEnum.h"
    
    UCLASS(meta = (BlueprintSpawnableComponent))
    class UNKNOWN_API AmultiBranch : public ActorComponent
    {
    	GENERATED_BODY()
    
    public:
    	UFUNCTION(BlueprintCallable, Meta = (FriendlyName = "MultiBranch", CompactNodeTitle = "MultiBranch", Keywords = "Multi Branch", ExpandEnumAsExecs = "Branches"), Category = Game)
    		void MultiRun(bool active, TEnumAsByte<EMultiBranchEnum>& Branches);
    };

CPP file:

#pragma once
#include "unknown.h"
#include "multiBranch.h"
#include "EMultiBranchEnum.h"

void AmultiBranch::MultiBranch(bool active, TEnumAsByte<EMultiBranchEnum>& Branches)
{
	if (active)
	{
		Branches = EMultiBranchEnum::BranchA;
		Branches = EMultiBranchEnum::BranchB;
	}
}

my Enums:

#pragma once

#include "GameFramework/Actor.h"
#include "multiBranch.generated.h"

UENUM(BlueprintActor)
enum class EMultiBranchEnum
{
public: 
	BranchA,
	BranchB
};

any help would be amazin XD

Get rid of CompactNodeTitle, you shouldn’t use compact node styling if it has exec pins.

What exactly is going on? Node does not appear or what? how does it not work? You didn’t said.

Also post reponce to anwser by posting comment to anwser, not as another anwser

The Node doesn’t show in the editor.

You placing function in component, so it wont show up in context menu unles from pin containing object of that component. Your node should be visible in Pallet tab which contains all function nodes should be visible. Pallet tab is closed by default, you need to open it from “Window” manu.

ok, but what do I need to switch out in the code?

nothing, it should be there, your code looks ok

ok? because it still isn’t there XD

Because it’s declared as a non-static member function on your UAmultiBranch (I’m assuming you lost the U prefix on the name when copying/pasting somehow, otherwise it wouldn’t compile) component class, it will only show up if you drag a blue pin/wire off of a reference to a UAmultiBranch component instance and then search for it in the popup window for adding nodes. It’s likely that you aren’t doing this, which is why you don’t see it when you right click in the Blueprint editor and try to add a node. You MUST find a blue pin/win wire that is a reference to a component instance and create the node from there, or from the node palette within the correct scope.

If you send a screenshot showing that this is not happening, then it’s a bug in UE4, but it’s almost certain that you’re misunderstanding what’s going on and doing it incorrectly from the Blueprint editor.

Well i told him to look on Pallet window, all function nodes (not sure about custom K2Nodes) are visible there regardless of class they came from

Yeah I think he is just doing something wrong or looking in the wrong place

Well your code looks ok, only think that looks odd is ActorComponent without U prefix, but that would trow you a error. you could try removing CompactNodeTitle = "MultiBranch" as Cancel said, but it’s just cosmetic feature, so it should not matter and besides if theres something invalid in UFUNCTION, UHT would not let you build your code.

Only idea that popup in my head just now is that this code file does not compile at all (which would explain why you not getting error from incorrect naming of UActorComponent), this happens when you add file using VS which will create file in Intermediate directory where UBT don’t look for code files. Can you check if you got that file in Source directory (but don’t look in VS, look in some disk browser)?

Yeah that was my next thought – his file isn’t compiling at all

Ok, sorry, took a small break from development, but:
I made an if instead, incase there is any incompatible use of branches (two branches that are called at the same time).
The code now:
EMultiBranchEnum.h:

#pragma once

#include "GameFramework/Actor.h"
#include "multiBranch.generated.h"

UENUM(BlueprintActor)
enum class EMultiBranchEnum
{
public: 
	BranchA,
	BranchB
};

multiBranch.h:

#pragma once

#include "GameFramework/Actor.h"
#include "multiBranch.generated.h"
#include "EMultiBranchEnum.h"

UCLASS(meta = (BlueprintSpawnableComponent))
class UNKNOWN_API UAmultiBranch : public UActorComponent
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintCallable, Meta = (FriendlyName = "Multi Branch", Keywords = "Multi Branch", ExpandEnumAsExecs = "Branches", ShortTooltip = "An IF node"), Category = Game)
		bool multiBranch(bool active, TEnumAsByte<EMultiBranchEnum>& Branches);
};

multiBranch.cpp:

#include "unknown.h"
#include "multiBranch.h"
#include "EMultiBranchEnum.h"

bool UAmultiBranch::multiBranch(bool active, TEnumAsByte<EMultiBranchEnum>& Branches)
{
	if (active)
	{
		Branches = EMultiBranchEnum::BranchA;
	}
	else
	{
		Branches = EMultiBranchEnum::BranchB;
	}
	return active;
}

I’ve check the placement of the files and all lies inside the Source folder. I corrected the ActorComponent to UActorComponent and AmultiBranch to UAmultiBranch. I looked in the pallet window and searched for “multi” but it only showed up with “add Multi Branch”:

and I pulled out a branch wire and got the same thing. It looked like this: (view the node picture)