I have the following code, which spawns a new static mesh component and attaches it to the character’s skeletal mesh at the specified socket. This code works perfectly in PIE, but places the mesh component at the root of the character when playing in a cooked build.
I originally thought this was a timing issue; I’m creating the skeletal mesh at runtime by combining other skeletal meshes. However, even after confirming the combined skeletal mesh is created (which also uses sockets for attachment) and triggering the equipping of the static mesh component (ie the item) the item still spawns at the root of the character (between their feet on the ground, rather than in their hand, in this particular case)
The item does move and rotate based on the character’s movement though, so it does seem attached; just in the wrong location.
EDIT: I’ve made some progress; code with no substantial differences works correctly for skeletal meshes, but for no static meshes I have. The static mesh component is created, it’s just attached at the root of the character’s skeletal mesh.
UStaticMeshComponent* ItemStaticMeshComp = NewObject<UStaticMeshComponent>(this, UStaticMeshComponent::StaticClass());
if (ItemStaticMeshComp)
{
ItemStaticMeshComp->RegisterComponent();
ItemStaticMeshComp->SetCollisionEnabled(ECollisionEnabled::NoCollision);
ItemStaticMeshComp->SetStaticMesh(ItemToEquip->EquippedMesh);
ItemStaticMeshComp->AttachToComponent(OwningSapphireCharacterSkeletalMesh,
FAttachmentTransformRules::SnapToTargetNotIncludingScale, OwningSapphireCharacter->GetSocketNameFromEquipEnum(ItemToEquip->ItemMetaData->ItemSocket));
ItemStaticMeshComp->SetRelativeTransform(ItemToEquip->EquippedMeshOffset);
}