How to properly set mesh and material to AActor ?

Hey guys, posting here as I found lots of answers to this basic question but none of them worked for me in 4.9.
I have an AActor and I simply want to set it a mesh and a material and see them in editor. Here is my code. If you see something wrong.


UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Meshes)
UStaticMesh* Hexagon;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Materials)
UMaterialInterface* Material;

UStaticMeshComponent* MeshComponent;

ATileGrid(const FObjectInitializer& ObjectInitializer);
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
	bool InitComponents();


ATileGrid::ATileGrid(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
	RootComponent = ObjectInitializer.CreateDefaultSubobject<USceneComponent>(this, "RootComponent");
	MeshComponent = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, "GridMesh");


	if (!InitComponents())
		UE_LOG(LogTemp, Log, TEXT("Couln't init components properly"));
		//TODO set default mesh and material
	bHiddenEd = 0;

bool ATileGrid::InitComponents()
	if (Hexagon)
		UE_LOG(LogTemp, Log, TEXT("Mesh set !"));
		MeshComponent->bOwnerNoSee = false;
		MeshComponent->bCastDynamicShadow = false;
		MeshComponent->CastShadow = false;


		return false;
	if (Material)
		UE_LOG(LogTemp, Log, TEXT("Material set !"));
		MeshComponent->SetMaterial(0, Material);
		return false;
	return true;

I always reach the logs in InitComponents() so it seems that my mesh and materials are set properly but nothing shows up.
Also sometimes I manage to see something working when I change my code a little bit and hot reload. But as soon as I change properties, everything is gone. :’(
void ATileGrid::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)

How do you set Material and Hexegon?

What do you mean by “browser”? You edit them in defaults or details on placed object in level?

They are exposed in the editor so set from the browser

Hum… i mean I have the usual mesh slot as available for any staticmeshcomponent so I drag my mesh from the minibrowser you have when clicking on it.
This happens after dragging my Actor in the scene. I have then access to its properties then i can set my mesh

I think the answer is details on placed object in level :slight_smile:

Fondamentaly whats the difference from grabbing the pointer from the ObjectInitializer than from the editor? My pointer is valid and properly assigned to the mesh component so there might be some extra initialization steps, i dont know

ObjectInitializer set objects in defaults when formally those object does not exist in memory. If you don’t have default mesh and material, i don’t see point of setting them in constructor. You should override PostEditChangeProperty as you did and set material and mesh there (which you kind of did and i think it should work), i would also would do that in PostInitializeComponents() because constructor is only called on CBO creation and won’t be called again, which means if you place it on level or game will start it would apply values of those variables from level data to components

" (which you kind of did and i think it should work)" This is the reason of my question: Changing the mesh and material in PostEditChangeProperty doesn’t work at all.

" i would also would do that in PostInitializeComponents()" I will but for now I am just trying to figure out how to make a custom c++ actor editable


As you can see, my GridMesh component has valid mesh and material (set in AtileGrid properties and assigned in C++ in PostEditChangeProperty) but nothing on screen. I tryed a MarkRenderStateDirty but nothing happens.


Fixed my issue… And now I feel dumb …