Can't create UMaterialInstanceDynamic

Hello
I have problem with creating dynamic material in c++.
Here is my actor constructor:
AVoxel::AVoxel(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
// Create the static mesh component
VoxelMesh = PCIP.CreateDefaultSubobject(this, TEXT(“VoxelMesh”));

	// Create Dynamic material
	TheMaterial_Dyn = UMaterialInstanceDynamic::Create(myMaterial, this);

	// Bind Tick function
	VoxelMesh->OnComponentHit.AddDynamic(this, &AVoxel::OnHit);
	
	// Set the BoxComponent as the root component
	RootComponent = VoxelMesh;

	// Turn on tick
	PrimaryActorTick.bCanEverTick = true;

}

myMaterial come from UPROPERTY asigned in deriver blueprint. I am sure it exist and is valid because when in print it to screen: myMaterial->GetName() i see my material name: HeatMaterial.
But after I create dyanmic material with: UMaterialInstanceDynamic::Create, when i print:

TheMaterial_Dyn->GetMaterial()->GetName() i see: WorldGridMaterial and it’s wrong because i need HeatMaterial.
How to fix it? :slight_smile:

Please refer to the link below:

Blueprint variable initialized after c++ constructor, so you can’t access it in your c++ constructor.

Please refer to the link below:

Blueprint variable initialized after c++ constructor, so you can’t access it in your c++ constructor.