Change the SkeletalMesh of a Character class

I created a class deriving from the basic character class. I want to write a function to change its SkeletalMesh-Component.

Now I know there is a variable “Mesh” in the Base Character class which contains the information about the Characters mesh. But how do I change/swap this mesh? Thanks

when I do it like “Mesh->SkeletalMesh = New_Mesh” it doesen’t change the mesh, but puts the old mesh in a t-pose position and cancels to play the idle animation.

Got it. The correct term is “Mesh->SetSkeletalMesh(New_Mesh);”

Mesh is a private variable in ACharacter, how does that work?

Oh that was a long time ago. Back then “Mesh” was public. Now you have to do it like “GetMesh()->SetSkeletalMesh(New_Mesh);” … I think

What is the proper way to load the mesh? The below doesn’t work.

static ConstructorHelpers::FObjectFinder New_Mesh(TEXT("SkeletalMesh'/Game/Mannequin/Character/Mesh/SK_Mannequin.SK_Mannequin'"));

I’ve seen references it’s bad to hardcode asset references, but I don’t understand how you could random or let the player select a new skin without this.

I think the Construction Helpers only work in the Constructor of a class.

It is bad practice to hardcode references to assets. In case you want to do it anyways write this in the constructor:

static ConstructorHelpers::FObjectFinder<USkeletalMesh> Mesh_Male_FeetObj(TEXT("SkeletalMesh'/Game/Characters/BodyParts/Male_Feet_LOD_0.Male_Feet_LOD_0'"));
	if (Mesh_Male_FeetObj.Object != NULL)
		Mesh_Male_Feet = Mesh_Male_FeetObj.Object;

“Mesh_Male_Feet” is a USkeletalMesh-pointer (declared in the header).

You could also just make the USkeletalMesh-pointer and specify the asset in the blueprint… I guess this would be the “right” way to do.