Why does my material keep breaking?

This issue is driving up the wall so much that I may stop using Unreal altogether. I have a UMaterialInstance pointer that I declare in a header file that I then assign as a default in a blueprint.

UPROPERTY(EditAnywhere, BlueprintReadWrite)
UMaterialInstance* ShieldMaterialInstance;
UMaterialInstanceDynamic* ShieldMaterialInstanceDynamic;

I set up this dynamic material in PostInitProperties:

void AOnyxPlayer::PostInitProperties()
{
    Super::PostInitProperties();
    if (ShieldMaterialInstance == nullptr) return;
    ShieldMaterialInstanceDynamic = UMaterialInstanceDynamic::Create(ShieldMaterialInstance, nullptr);
    ShieldMaterialInstanceDynamic->SetScalarParameterValue(
        TEXT("Thickness"), ShieldThickness
    );
    ShieldMesh->SetMaterial(0, ShieldMaterialInstanceDynamic);
}

I make a material, a new material instance with that material as a reference, and then I assign the material instance to this material instance pointer. It works initially in the editor and in the viewport. However, literally doing anything breaks it. Making a change in the C++ breaks it, going to standalone mode breaks it, saving the material breaks it. What is going on here?

Here’s a GIF.

As you can see, in the editor it’s got this weird broken material. I have to compile the blueprint repeatedly to get it work in the editor or the viewport. Any have any ideas?

I gave up and switched to blueprints. Endlessly frustrating.