Attaching UStaticMeshComponent to Sockets Not Working

BatonHand = CreateDefaultSubobject(TEXT(“Baton Active”));
BatonHip = CreateDefaultSubobject(TEXT(“Baton Sheath”));
BatonHand->AttachToComponent(this->GetMesh(), FAttachmentTransformRules::SnapToTargetIncludingScale, FName(“batonhand”));
BatonHip->AttachToComponent(this->GetMesh(), FAttachmentTransformRules::SnapToTargetIncludingScale, FName(“batonsheath”));

Does anyone know why these meshes refuse to attach to their parent sockets? I’ve checked like 8 times and the sockets exist with those exact names, and are attached to hand_r and spine_01 in the player’s skeletal mesh respectively.

I’m performing this in the constructor if that helps.

Try using SetupAttachment(GetMesh(), FName("batonhand")); instead.

So the update code would look like this

BatonHand = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Baton Active"));
BatonHand->SetupAttachment(GetMesh(), FName("batonhand"));

BatonHip = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Baton Sheath"));
BatonHip->SetupAttachment(GetMesh(), FName("batonsheath"));