[c++] How to create a new skeletal mesh from a class

Hello,

I am trying to set up a custom player controller and pawn in code based on the c++ Third Person demo. In the constructor for my pawn, the ObjectInitializer one, I am adding a capsule component, skeletal mesh component, and camera component to my pawn. I wanted to try and add the test skeletal mesh component ‘ThirdPersonSkelMesh’ found in the Editor content as a new mesh using SkeletalMeshComponent->SetSkeletalMesh().

How can I create an instance of this class in code? I’ve been looking at the CreateDefaultSubobject function, but don’t see a way to specify how to create that class. Please help! Thanks.

In constructor you can use this

static ConstructorHelpers::FObjectFinder<USkeletalMesh> VariableName(TEXT("SkeletalMesh'/Refrence/To/Mesh.Mesh'"));

VariableName will be instance of refrenced skeletal mesh, name does not need to be VariableName ofcorse. To get reference path, right click asset and click “Copy Reference” it will copy path to clipboard. You can use that not only for skeletal mesh but other assets to, you just need to use right class instead of USkeletalMesh, for example UStaticMesh, USoundCue, UMaterial etc.

Note that you can also use those pointers to those classes and expose them to blueprint, this way in defaults and details you will have asset picker and you can set asset to varable

Ah, also remeber to decler varable first, this case it would be

UPROPERTY()
USkeletalMesh* VariableName;

This is exactly what I was looking for, thank you.