Cannot figure out what is wrong with this code to change the material of a basic mesh in C++

I’m pretty sure the problem is UMaterialInstanceDynamic::Create or something called indirectly from there. I’ve tried to use this function in a constructor before as well and the project would no longer load anymore and crash at startup. Moving the MaterialInstanceDynamic (MID) creation to my Actor’s BeginPlay function worked for me. Not really sure what the “preferred” function/place for creating them in code is. Usually when you just need to create them and update their parameters once you can do it “on demand” whenever you need it but what if you want to constantly update them? Creating the MID and initializing the parameters to the desired/resonable defaults in the constructor seems like the ideal place.

Other than that using the UPROPERTY approach only really works if you can actually use a Material or MaterialInstanceConstant but if you want to change the parameters at runtime you “have” to use UMaterialInstanceDynamic (see workaround here: Set Material of Landscape). You can still use the UPROPERTY as the parent for the MID though. It’s a bit limiting if UMaterialInstanceDynamic can indeed not be created from UCLASS constructors (or did I miss something?).