How to load a static mesh ? c++

A static mesh is not an AActor, it’s a UObject, casting it to AActor will always give you a null pointer.

Also, when you Cast, you need to include the class you’re casting to as a template argument.

Try this:

UStaticMesh* Mesh = Cast<UStaticMesh>(StaticLoadObject(UStaticMesh::StaticClass(), nullptr, TEXT("/Game/MeshName")));

or:

UStaticMesh* Mesh = LoadObject<UStaticMesh>(nullptr, TEXT("/Game/MeshName"));
1 Like