How can I allow a material to be changed from the Editor in an Actor Derived Class?

After following and adding to the Procedural Mesh Generation Tutorial on the Wiki I have a procedurally generated Quad, that has UV’s and also has a Material assigned to it during Construction. I have added a UPROPERTY for a UMaterial (Now that shows up in the editor). Also in the constructor it is that very material that I load the material into, then “SetMaterial” on my mesh component with. My Class declaration looks like this:

class AGeneratedFloorQuad : public AActor

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Materials)
	UMaterial *GroundMaterial;

	TSubobjectPtr<UGeneratedMeshComponent> mesh;
	float HALF_SIZE = 500.f;


And in the constructor:

... left out vert crap
static ConstructorHelpers::FObjectFinder<UMaterial> mat(TEXT("/Game/Materials/Tri_Proj"));
	GroundMaterial = mat.Object;
	mesh->SetMaterial(0, GroundMaterial);
	RootComponent = mesh;

When I change the material in the editor it changes the material shown in the properties box, but not on the mesh component of the actor. How do I go about making it change the material on the mesh component of the actor?


What you want is described here:

I’ve done this myself so I know it works

You can override this function to check for your when your property is changed and then update the component yourself.

the key part is GetNameCPP which = the variable name:

//Actual property name! like "TileName"
UE_LOG(Victory,Warning, TEXT("prop changed ~Name~ %s"), *PropertyThatChanged->GetNameCPP());


This is exactly what I was looking for. I knew there had to be some sort of event to hook into, or in this case override. You are the man Rama. If I still drank, and you lived close I would buy you a beer or 10. Thank You.