How do I make my AActor's static mesh appear at runtime?

I’m building the Actor base class that every interactable item in the world will extend from, and I’m a bit confused on how to actually associate the class with physical geometry. I have a reference to a static mesh that I can set from the editor:

UPROPERTY(EditAnywhere)
UStaticMesh* objectMesh;

However, the actor’s blueprint is invisible when I drag it into the level; what do I need to do in order to actually spawn the static mesh at the actor’s root transform?

You need a UStaticMeshComponent

.h
public:
UPROPERTY(EditDefaultsOnly)
UStaticMeshComponent* MyStaticMeshComponent;

.cpp
// Sets default values
ATestActor::ATestActor()
{

	PrimaryActorTick.bCanEverTick = true;
	MyStaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>("MyStaticMeshCom");
	RootComponent = MyStaticMeshComponent;

}

This is just a reference variable. You will want to have a StaticMeshComponent!

Here is a code example on how i create my StaticMeshComponent, where i set my real StaticMesh in Blueprints, like you would normally do.

In my header, i have a public variable:

UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "Item Config")
		class UStaticMeshComponent* ItemStaticMesh;

And in my cpp file, i do the following in the Constructor:

ItemStaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(FName("ItemStaticMesh"));
	ItemStaticMesh->bReceivesDecals = false;
	ItemStaticMesh->bCastDynamicShadow = true;
	ItemStaticMesh->SetOnlyOwnerSee(false);
	ItemStaticMesh->SetOwnerNoSee(false);
	
	RootComponent = ItemStaticMesh;

The extra options (bReceivesDecals) are not necessary, but you will want to check what you can set for this StaticMesh.

That works perfectly!! Thank you so much :slight_smile:

Wups, i had this question open so long, that i didn’t update it x) So nevermind my comment. Thanks Mhousse1247 for that (: