SGraphNode has an empty constructor? How to create new node?

Hi, I’m trying to create a new custom node in my plugin but I’m having a bit of a problem. I have this NodeFactory here:

struct FDialogGraphNodeFactory : public FGraphPanelNodeFactory
{
public:
	virtual ~FDialogGraphNodeFactory() {}
	virtual TSharedPtr<class SGraphNode> CreateNode(class UEdGraphNode* Node) const override
	{
		if (UDialogGraphNode* NodeAsDialogNode = Cast<UDialogGraphNode>(Node)){
			return SNew(SDialogGraphNodeWidget, NodeAsDialogNode);
		}
		return nullptr;
	}
};

In my class derived from SGraphNode I have this:

class SDialogGraphNodeWidget : public SGraphNode
{
public:
	SLATE_BEGIN_ARGS(SDialogGraphNodeWidget)
	{}

	SLATE_END_ARGS()
	
	void Construct(const FArguments& InArgs, UEdGraphNode* InNode)
	{
		SGraphNode::Construct(); // This constructor is actually in SPanel and not in SGraphNode. It's also empty
	}
};

The problem is that in the factory when I try to return SNew(SDialogGraphNodeWidget, NodeAsDialogNode); I get an error saying that the Constructor takes no arguments. My question is: if the constructor takes no arguments, how am I supposed to use SNew()? SNew() can’t be empty, but you also can’t add anything to it?

Can someone help me make sense of this?

When I try running as is. I get this unresolved external error, pointing to this function here. I have Slate and SlateCore in my dependencies, I have also included Slate in the header files. Any ideas?

No one?

I used this function to replace the widget:

TSharedPtr<SGraphNode> UOGNode_ComboGate::CreateVisualWidget()
{
	return SNew(SGraphNodeOGComboGate, this);
}

*I don’t remember why I did it this way a long time ago, but it worked… :sweat_smile:
I probably had problems with the factory just like you did…

Hello @eliasfrost ,
There’s no need to call Construct in your class derived from SGraphNode. Instead, the widget should be built inside UpdateGraphNode, as that’s the method intended for constructing and updating the node’s content.


Regarding the linking error, it’s most likely because the EditorStyle module isn’t linked in your YourProjectEditor.Build.cs . As a recommendation, instead of using FEditorStyle, you should use FAppStyle, as it’s the recommended API in newer versions of the engine.

Finally, don’t forget to register your GraphNodeFactory during your module’s initialization ; otherwise, the editor won’t be able to use your custom node implementation.
image

Hope it helps!

1 Like