How do I get an Actor's static mesh?

I have an AActor * type. How do I get it’s static mesh?

When I look at the Actor in the editor, I can see in the root component it has a Static Mesh set. I can see it in the content browser.

However, in C++, I can’t seem to be able to access that Static Mesh? There seems no way to get to it.

I had tried casting my actor from AActor * to AStaticMeshActor * but I keep getting a NULL back.

AActor * rootComponent = GetOwner();
AStaticMeshActor *	staticMesh = Cast<AStaticMeshActor>(rootComponent);

It seems like a simple thing to do, how do you access the static mesh from an actor?

1 Like

Try this:

TArray<UStaticMeshComponent*> Components;
for( int32 i=0; i<Components.Num(); i++ )
    UStaticMeshComponent* StaticMeshComponent = Components[i];
    UStaticMesh* StaticMesh = StaticMeshComponent->StaticMesh;

Thank you. I am a total UDK newbie and with every answer I learn a bit more about the engine.

That’s the spirit!

Hi. This is like three years from the original answer, but consider using the public function GetStaticMesh() instead of ->StaticMesh. I got an error. Thanks.

Or if you just want to get the ONE static mesh that it has, you can take the first by doing: UActorComponent* comp = GetComponentByClass(UStaticMeshComponent::StaticClass()); . You would have to use Casting to change UActorComponent to the specific StaticMesh Component you have.

How do i get the name of the StaticMesh?