I have a slate SImage brush which displays a material through FSlateBrush.
The FSlateBrush displays a material. The material has some parameters which I want to edit dynamically. I want to edit them depending on some conditions.
I cant find any variables in FSlateBrush to edit material. So is there a way to edit material per instance of slate SImage widgets or any other Widget to edit materials.
just in case, I had side effect in non editor version in 4.7 with dynamic material. The material was dropped about 30sec after the first usage (surely garbagged). So test that in standalone game before moving to far with this code ^^
I didn’t find a solution for my issue, I try to talk on it on answerhub without solution as of now. So I move this part in UMG and that solve my problem.
Elvince, you could use the AddToRoot method to prevent the material being garbage out.
F.e.
auto ConstInst = Cast<UMaterialInstanceConstant>(
FSoftObjectPath("path/to/some/material'").TryLoad());
auto DynamicInst = UMaterialInstanceDynamic::Create(ConstInst, nullptr);
DynamicInst->AddToRoot(); // Prevent the dynamic material being GC
At least, UE5 has this option. I didn’t test this in prev versions.
I hope, this will help anyone