How to change the icon displayed on custom node or macro?

Hello,

I’m looking for a way of changing the icon that displays on macro nodes or custom nodes placed in Blueprint Graph.

Many of default Unreal nodes use custom icons so I believe this is somehow possible to do.
Espesially the ...\Engine\Content\EditorBlueprintResources\StandardMacros.uasset has so many stuff with cutom icons in it:

I already tried to reverse engineer the logic behind it and found this .cpp::
https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Editor/BlueprintGraph/Private/K2Node_MacroInstance.cpp
In which there is code that probably handles the replacement of icons:

FSlateIcon UK2Node_MacroInstance::GetIconAndTint(FLinearColor& OutColor) const
{
	const char* IconName = "GraphEditor.Macro_16x";

	// Special case handling for standard macros
	// @TODO Change this to a SlateBurushAsset pointer on the graph or something similar, to allow any macro to have an icon
	UEdGraph* MacroGraph = MacroGraphReference.GetGraph();
	if(MacroGraph != nullptr && MacroGraph->GetOuter()->GetName() == TEXT("StandardMacros"))
	{
		FName MacroName = FName(*MacroGraph->GetName());
		if(	MacroName == TEXT("ForLoop" ) ||
			MacroName == TEXT("ForLoopWithBreak") ||
			MacroName == TEXT("WhileLoop") )
		{
			IconName = "GraphEditor.Macro.Loop_16x";
		}
		/* There is just more else-if's that works exacly the same way as the if statement above */
	}
	return FSlateIcon("EditorStyle", IconName);
}

But I’m not really sure what shall I do with all of it since I’ve never used K2Node_MacroInstance.h.

How can I apply the same icon-swapping logic for custom nodes/macros that I’ve created in my project/plugin ?

I’ll really appreciate any answers :slight_smile:
Also this topic was partially asked (but not answered) in this very old post:

I did not implement any custom nodes myself, but yesterday by chance I came across this article on gamedev.net when searching for other things, and maybe it could be useful for you. I did not get further into it, but there’s quite some info in the article about icons…
I hope, you find some useful information in there.

1 Like

So it looks like inheriting from K2Node class and overwriting its functions can do it.
Still don’t know how to implement this in typical function library.
Tho thanks for the article