Download

Crash opening a StaticMesh in editor after adding some StaticMaterials to it

Here is this basic code, that worked in previous versions of UE4, anyway it still compiles without any problem.

//get the material itself
UMaterialInstanceConstant *FoundMaterial = FindObject<UMaterialInstanceConstant>(ANY_PACKAGE, FixedMaterialName.GetCharArray().GetData());

//if the material exists add it
if (FoundMaterial != nullptr)
{
FName MaterialFName = FName(“A”);
FStaticMaterial smat(FoundMaterial);
smat.ImportedMaterialSlotName = MaterialFName;
smat.MaterialSlotName = MaterialFName;
StaticMesh->StaticMaterials.Add(smat);
}

if I don’t add the smat to StaticMaterials everything looks ok (but obviously I have no materials applied), notice that also it doesn’t crash on adding it but when I try to open that StaticMesh in the editor or if I place it in the viewport.

Any tip on this?

PS. note that I’m referring to UStaticMesh not a component neither an actor.