Preview Meshes for C++ Actors

Hello!

I’m struggling abit with setting a preview-mesh using C++. I’ve created an actor class and a UStaticMeshComponent called “CurrentMesh” within it which I want to assign a static mesh to. I have also made a TArray of static meshes (which is blank until it’s edited in blueprints) which the UStaticMeshComponent can choose meshes from. If the index 0 of this array has been assigned I want to apply the mesh of it to my UStaticMeshComponent, although I don’t know how to accomplish this.

My main idea was to assign it in PostInitProperties, but whenever I compiled it would just return a breakpoint in Array.h. Here’s the breakpoint:

Now, I see that checkf checks if the index is greater than the array length, so I put it into an if-statement which checks if the array-index is valid:

void ADefaultPlantActor::PostInitProperties()
{
	Super::PostInitProperties();

	if (MeshStages[0])
	{
		CurrentMesh->SetStaticMesh(MeshStages[0]);
	}
}

Although this didn’t fix anything, and just returned to the same breakpoint. And if this helps: I’m using uint8 for my array.

Does anyone know how I would accomplish this? I simply want to display a mesh/preview mesh for the actor whenever I’m in the editor. Think of it as the blueprint-construct; you drag out from the construct node and set a static mesh like this:

Thanks in advance! :slight_smile:

~Stefan