In my Actor constructor, I set the Material like this:
static ConstructorHelpers::FObjectFinder<UStaticMesh> StaticMesh(TEXT("StaticMesh'/Game/StarterContent/Shapes/Shape_Cube'"));
static ConstructorHelpers::FObjectFinder<UMaterial> Material(TEXT("MaterialInstanceConstant'/Game/StarterContent/Materials/M_Ground_Moss'"));
this->MyBlock = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("SolidBlock"));
this->MyBlock->SetStaticMesh(StaticMesh.Object);
this->MyBlock->SetMaterial(0, Material.Object);
And when I spawn the Actor, I do the following:
AActor* CubeActor = world->SpawnActor<AWorldCube>(AWorldCube::StaticClass(), location, rotation);
However, this doesn’t seem to leave me options when wanting to change the Material, or initialize the class with a different Material than what is hardcoded (Maybe I want to block to turn to gold after the player has walked near it…who knows…)
Should I create several different cube classes for each material?
Or is there a way to modify the Material of a given Actor after spawn?
Or perhaps spawning with ::StaticClass() is the issue?
I am too new to Unreal to overcome this issue it seems. Help appreciated.