Load Static Mesh With Path in c++

First you will need to create a default subobject in your constructor:

mesh = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("mesh"));

Then, to set the actual mesh to use (can be done from anywhere):

UStaticMesh* meshToUse = Cast<UStaticMesh>(StaticLoadObject(UStaticMesh::StaticClass(), NULL, TEXT("pathToYourAssetHere")));

if(meshToUse && mesh)
{
    mesh->SetStaticMesh(meshToUse);
}

Please note that you will have to declare “mesh” as a class variable.

1 Like