Hey, I have what I hope will be an easy question. In the following code I want to create a Slate brush to pass to a widget but although this code compiles I know that as soon as the function ends the brush will go out of scope and I will be dereferencing nullptr. How can I create this brush so that doesn’t happen and unreal manages the pointer?
UMaterialInstance* ArmorBase = Cast<UMaterialInstance>
(FSoftObjectPath("Content/Materials/MI_ArmorStatus").TryLoad());
ArmorStatusMaterial = UMaterialInstanceDynamic::Create(ArmorBase, nullptr);
ArmorStatusMaterial->AddToRoot(); // Prevent the dynamic material being GC
FSlateMaterialBrush ArmorBrush = FSlateMaterialBrush(FVector2D(100, 100));
ArmorBrush.SetResourceObject(ArmorStatusMaterial);
ChildSlot[
SNew(SOverlay)
+ SOverlay::Slot().HAlign(HAlign_Fill).VAlign(VAlign_Fill)
[ SNew(SImage).Image(&ArmorBrush) ]
];