Reference

How do i reference a material instance in my .h file so that i dont have to do it in my blueprint so they are defaulted?

This is what i am currently using



UPROPERTY(EditDefaultsOnly, Category = "HitDecals")
	class UMaterialInstance* PlasterDecal;


And this is how i want it to be so it is defaulted. I know that it wont work like this but how can i make it so that it is set to it automatically.
This is the name of the material (M_PlasterDecals_Inst)



UPROPERTY(EditDefaultsOnly, Category = "HitDecals")
	class UMaterialInstance* M_PlasterDecals_Inst;


You don’t reference a material instance, you rather create one.
If M_PlasterDecals_Inst is the name of a MID you created in editor:


// .h

	UPROPERTY(EditAnywhere, Category = "Material")
		UMaterialInterface *ParentMaterial;

	UPROPERTY()
		UMaterialInstanceDynamic *MaterialInstance;

// .cpp

// constructor
SomeClass::SomeClass()
{
	static ConstructorHelpers::FObjectFinder<UMaterial> MaterialResource(TEXT("Material'/Path/To/M_PlasterDecals_Inst.M_PlasterDecals_Inst'"));
	if (MaterialResource.Succeeded())
	{
		ParentMaterial = MaterialResource.Object;
	}

And then you create the material instance like this (in BeginPlay() for example, I don’t remember very well but I believe it won’t work in constructor):


	MaterialInstance = UMaterialInstanceDynamic::Create(ParentMaterial, this);

This code is from 4.10 if I’m not mistaken