access materialinterface at runtime

I making a tmap storing data with materialinterfaces as keys.

TMap<UMaterialInterface*, FMaterialAttribute> NewMaterialMap;
UMaterialInterface* MaterialMapKey = TempComponents[j]->GetMaterial(k);
FMaterialAttribute MaterialMapValue = FMaterialAttribute();
FLinearColor MaterialAttribute1;
FLinearColor MaterialAttribute2;
FLinearColor MaterialAttribute3;
FLinearColor MaterialAttribute4;
UE_LOG(LogTemp, Warning, TEXT("4.1"));
UE_LOG(LogTemp, Warning, TEXT("%s"),*MaterialMapKey->GetName());
if (MaterialMapKey->GetVectorParameterValue("MaterialAttribute1",MaterialAttribute1))
{
	UE_LOG(LogTemp, Warning, TEXT("4.2"));
	MaterialMapValue.MaterialParamSet1.X = MaterialAttribute1.R;
	MaterialMapValue.MaterialParamSet1.Y = MaterialAttribute1.G;
    MaterialMapValue.MaterialParamSet1.Z = MaterialAttribute1.B;
	UE_LOG(LogTemp, Warning, TEXT("4.3"));
}
NewMaterialMap.Add(MaterialMapKey, MaterialMapValue);

when i call this in the editor via a blutility it all works fine.
but when i try this in the beginplay event it crashes as soon as it tries to acces the MaterialMapkey.

any suggestions?

thanks in advance

i dont want to change the parameter i just want to read them. this should just be passiv, thats why i dont create an meterial instace.

it already crashes at MaterialMapKey->GetName()

Well BeginPlay can be tricky sometimes…

First check if this is a multiplayer game… beginplay will run both server and client… server does not have any render modules, so i guess GetVectorParameter would not run properly…

Second: im not sure about this, but…

i think you should create dynamic material instance before you try get any parameter from material because whatever is the material is an instance of any master thats applied as non dynamic material?!

     virtual void BeginPlay() override
     {
         //create dynamic material anywhere u like, Constructor or anywhere .
         UMaterialInstanceDynamic* DynMaterial = UMaterialInstanceDynamic::Create(Material, this);
         //set paramater with Set***ParamaterValue
         DynMaterial->SetScalarParameterValue("MyParameter", myFloatValue);
         MyComponent1->SetMaterial(0, DynMaterial);
         MyComponent2->SetMaterial(0, DynMaterial);
         //...
     }

Im really not sure about this but give it a try

im not sure you can still get params just from materialinterface if no dynamic material applied to mesh… since material instances creating non runtime readable materials . as i know… maybe im false

Ohm if crash on getname… your pointer is invalid obviously… maybe “k” is not resulting right material?

yeah obviosly … but why? as i said when i run the same function in editor mode it works just fine.
is there any restriction on accessing materials at runtime? i can’t find any info about this and giving the fact the interface class is under the runtime section it confuses me a little