Skip to content

Instantly share code, notes, and snippets.

@rtm223
Last active January 16, 2026 18:28
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
// The MIT License
// Copyright (c) Richard Meredith AB
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//-----------------------
// 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