Skip to content

Instantly share code, notes, and snippets.

@rtm223
Created September 20, 2025 10:58
Show Gist options
  • Select an option

  • Save rtm223/329b4ac7b7f9757c016fa9d36586c8b5 to your computer and use it in GitHub Desktop.

Select an option

Save rtm223/329b4ac7b7f9757c016fa9d36586c8b5 to your computer and use it in GitHub Desktop.
Creating a standalone Material Function Expression Node Widget
// Minimum code for standing up an SGraphNodeMaterialBase for a material fucntion
// Note, the various UObjects created here (material etc.) are probably not being kept alive and may be GC'd so will want strong refs if you want to keep your widget alive
UMaterial* material = NewObject<UMaterial>(outer, NAME_None, RF_Standalone | RF_Public);
auto* expression_materialFunction = Cast<UMaterialExpressionMaterialFunctionCall>(UMaterialEditingLibrary::CreateMaterialExpressionEx(material, nullptr, UMaterialExpressionMaterialFunctionCall::StaticClass(), materialFunction));
UMaterialGraph* graph = NewObject<UMaterialGraph>();
graph->Schema = UMaterialGraphSchema::StaticClass();
UMaterialGraphNode* node = graph->AddExpression(expression_materialFunction, true);
TSharedRef<SGraphNodeMaterialBase> nodeWidget = SNew(SGraphNodeMaterialBase, node);
TArray<TSharedRef<SWidget>> pins;
nodeWidget->GetPins(pins);
for(auto pin : pins)
{
TSharedRef<SGraphPin> sPin = StaticCastSharedRef<SGraphPin>(pin);
sPin->SetDiffHighlighted(false);
}
nodeWidget->MarkPrepassAsDirty();
nodeWidget->SlatePrepass();
@rtm223
Copy link
Author

rtm223 commented Sep 20, 2025

Editor only (obvs)

This node can be rendered out using a widget renderer, or can be placed in any slate hierarchy. It won't be interactable, but all node tooltips (for input/output descriptions should function correctly)

image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment