Error Saving Level When a actors static mesh Uses SetVectorParameterValueOnMaterials C++

Hi

I am new to unreal engine and having trouble with using this function on an actor’s static mesh SetVectorParameterValueOnMaterials in C++.

It applies changes to the material successfully but when i go to save the level that it resides in i can’t and i get the following error.

Can’t save BasicLevel.umap: Graph is linked to external private object MaterialInstanceEditorOnlyData /Script/CPP.Default__GridModifier:Mesh.MaterialInstanceDynamic_0.MaterialInstanceDynamic_0EditorOnlyData (EditorOnlyData)

I call it like so
mesh->SetVectorParameterValueOnMaterials(FName(“Color”),
FVector(FLinearColor(1.0f, 0.0f, 0.0f, 1.0f)));

if i dont call it level saves

I fixed it by implementing

void AMyActor::OnConstruction(const FTransform& Transform)
{

Super::OnConstruction(Transform);
Construct();

}

and in the construct function

UMaterialInstanceDynamic* material =
UMaterialInstanceDynamic::Create(mesh->GetMaterial(0),mesh);
material->SetVectorParameterValue(FName(“Color”),
FVector(FLinearColor(1.0f, 0.0f, 0.0f, 0.5f)));
mesh->SetMaterial(0, material);