Created
September 20, 2025 10:58
-
-
Save rtm223/329b4ac7b7f9757c016fa9d36586c8b5 to your computer and use it in GitHub Desktop.
Creating a standalone Material Function Expression Node Widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)