Modular pawn skeleton components out of position

I am creating a modular pawn by adding 2 meshes with same skeleton together using a ACharacter class in C++.

I use the following code :

headAndArmsComponent->SetSkeletalMesh(HeadAndArmsMesh);
headAndArmsComponent->SetMasterPoseComponent(GetMesh());
headAndArmsComponent->AttachParent = GetMesh();

however when the player spawns the Head is way far in the air from the rest of the body, however the animations runs correctly (With head still in air) and it also follows the parent mesh’s rotation

Although adding components in persona animation viewer works correctly

LOL I’m stupid! All I had to do was set the child skeletal mesh component position to that of parent mesh component.

By default the Engine creates each new component at world origin and then the actor keeps that as the relative position

In short I had to add the following line

headAndArmsComponent->SetWorldLocation(GetMesh()->GetComponentLocation(), false);

where GetMesh() gives the default/parent Mesh component in a ACharacter class!

Hope this will help future new comers

Thanks for the info! Just to clarify does this allow you to swap out the “head and arms” of you character? I am wanting to implement an armor system where people can equip helmets and chest armor. Just wondering if this is the way to do it. Thanks!

well yes you can for sure, but you’ll need to call following each time you wish to change the heads and arms (In your case the armor)

headAndArmsComponent->SetSkeletalMesh(HeadAndArmsMesh);