It seems the following code causes the crash (located in PostInitializeComponents):
//Get and assign Material Instance
if (Pickup_Material != NULL)
{
//Pickup_Material is a UMaterialInstanceDynamic, inherited from the parent class
Pickup_Material->SetVectorParameterValue(FName(TEXT("Tint")), ColorTint);
TArray<FSkeletalMaterial> CharMats;
if (SkelMesh_Gear_Male != NULL)
{
CharMats = SkelMesh_Gear_Male->Materials;
for (int32 iMats = 0; iMats < CharMats.Num(); iMats++)
{
if (SkelMesh_Gear_Male->Materials[iMats].MaterialInterface == Pickup_Material_Origin)
{
SkelMesh_Gear_Male->Materials[iMats].MaterialInterface = Pickup_Material;
}
}
}
if (SkelMesh_Gear_Female != NULL)
{
CharMats = SkelMesh_Gear_Female->Materials;
for (int32 iMats = 0; iMats < CharMats.Num(); iMats++)
{
if (SkelMesh_Gear_Female->Materials[iMats].MaterialInterface == Pickup_Material_Origin)
{
SkelMesh_Gear_Female->Materials[iMats].MaterialInterface = Pickup_Material;
}
}
}
}
A possibility could be that the Material Instance “Pickup_Material” (which is declared in the parent class of this actor) causes the crash, because I am re-using it on a skeletal mesh of the child class. I read that this causes a memory leak in the packaged project. How can I resolve this?
Thanks in advance