Attaching static meshes to sockets c++

So i am trying to put static meshes into my characters arm socket via c++.
I have a pickup system that puts the mesh i pick up from the world to next to me but i want to change it to put the mesh to my hand socket i have made.
const USkeletalMeshSocket* socket = GetMesh()->GetSocketByName("Hand"); HoldingComponent->AttachToComponent(socket, FAttachmentTransformRules(EAttachmentRule::SnapToTarget, true));
I think this code is right for the most part but it gives me a error that says: E0167 argument of type “const USkeletalMeshSocket *” is incompatible with parameter of type “USceneComponent *” on the second line of code.
I could use some help!

Hey there!

So by Default AttachToActor and AttachToComponent take an optional last parameter called SocketName. So all you should need to do here is HoldingComponent->AttachToComponent(GetMesh(), FAttachmentTransformRules(EAttachmentRule::SnapToTarget, true), TEXT("Hand"));, and unless there are other issues in your code, that should be it I believe :slight_smile:

Also, to give a bit more explanation: GetMesh()->GetSocketByName("Hand") is actually returning some metadata about the Socket on that mesh (if it exists), and from what I’ve seen glancing at the source is mainly used in the Editor, not at runtime (though this may be incorrect).

Hope this helps!

Thank you appericiate the help:)