Mesh->SetSkeletalMesh(?);

Hi there,

in the constructor of my character-derived-class i have the following:

static ConstructorHelpers::FClassFinder MyMeshOb(TEXT("/Game/SkeletalMeshes/SKM_MyMesh"));

Mesh->SetSkeletalMesh(MyMeshOb.Class);

which is obviously wrong :frowning:

(error: no suitable conversion function from “TSubclassOf” to “USkeletalMesh *” exists)

I’m absolutely new to c++ and try learning it from unreal engine like i made my first programming/scripting
experiences with uscript.
If i had found references in the source i would have used them, but i didn’t find any.

Thanks

Hey,

here is the way the “Shooter Tutorial” set up the Mesh.

CharacterClass.h

UPROPERTY(VisibleDefaultsOnly, Category = Mesh)
	TSubobjectPtr<USkeletalMeshComponent> FirstPersonMesh;

CharacterClass.cpp

FirstPersonMesh = PCIP.CreateDefaultSubobject<USkeletalMeshComponent>(this, TEXT("FirstPersonMesh"));

You can setup the Model later in the BP or i guess in the cpp file itself by refering to it.

Also if you made a class of the StandardCharacterClass of the UE4. There should be a simple “Mesh” you can access.
They also do this in the Shooter Tutorial to set its Visibility to “OwnerNoSee(true)”.

EDIT: Ah, and to get the Mesh you have in your ContentFolders, i guess you can do it with this:

static ConstructorHelpers::FObjectFinder<UTexture2D> 
CrosshairTexObj(TEXT("Texture2D'/Game/Textures/crosshair.crosshair'"));
CrosshairTex = CrosshairTexObj.Object;

CrosshairTex is defined in the .h file like this:

UTexture2D* CrosshairTex;

Thats how the Shooter Tutorial got the crosshair Texture.
I guess you can do the same with a mesh.

Thank you very much.

Your hint with the “FObjectFinder” was the right syntax i needed:

static ConstructorHelpers::FObjectFinder MyMeshOb(TEXT(“SkeletalMesh’/Game/SkeletalMeshes/SKM_MyMesh.SKM_MyMesh’”));

Mesh->SetSkeletalMesh(MyMeshOb.Object);

My goal is to avoid Blueprint as much as possible, so i wanted to assign my custom SkeletalMesh to the already existing Mesh of ACharacter.