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.

.h

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

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

UStaticMeshComponent* MeshComponent;

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

.cpp

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

	MeshComponent->AttachTo(RootComponent);

	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->SetStaticMesh(Hexagon);
		MeshComponent->bOwnerNoSee = false;
		MeshComponent->bCastDynamicShadow = false;
		MeshComponent->CastShadow = false;

		//Visibility
		MeshComponent->SetHiddenInGame(false);

		//Mobility
		MeshComponent->SetMobility(EComponentMobility::Movable);
	}
	else
	{
		return false;
	}
	if (Material)
	{
		UE_LOG(LogTemp, Log, TEXT("Material set !"));
		MeshComponent->SetMaterial(0, Material);
	}
	else
	{
		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)
{
InitComponents();
}

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

63816-bug.jpg

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.

Super::PostEditChangeProperty(PropertyChangedEvent);

Fixed my issue… And now I feel dumb …