# Snap a mesh socket to another socket

**URL:** <https://forums.unrealengine.com/t/snap-a-mesh-socket-to-another-socket/338279>\
**Category:** Asset Creation\
**Tags:** sockets, unreal-engine, snap, question\
**Created:** [November 12, 2015, 5:38pm UTC](https://forums.unrealengine.com/t/snap-a-mesh-socket-to-another-socket/338279 "2015-11-12T17:38:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Komahz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Komahz](https://forums.unrealengine.com/u/Komahz)\
**Post date:** [November 12, 2015, 5:38pm UTC](https://forums.unrealengine.com/t/snap-a-mesh-socket-to-another-socket/338279/1 "2015-11-12T17:38:32Z")

</div>

How i can make a mesh socket to snap to another mesh socket? It’s a bit hard to explain for me but look the picture.

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/3X/f/e/fe63e85fedca919c765e267d70fc090cd5093ffa.png)

---

<div class="post-metadata">

**Author:** ![rantrod](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rantrod](https://forums.unrealengine.com/u/rantrod)\
**Post date:** [December 22, 2015, 1:39am UTC](https://forums.unrealengine.com/t/snap-a-mesh-socket-to-another-socket/338279/2 "2015-12-22T01:39:10Z")

</div>

I’m doing this on the fly off the top of my head so there might be errors, but something like this:

```
FTransform SocketTrans= MyActorB->GetMesh()->GetSocketTransform() * MyActorB->GetTransform().Inverse();
MyActorB->AttachRootComponentTo(/*ActorA*/GetMesh(), "ActorASocket", EAttachLocation::SnapToTarget, true);
FRotator DesiredLocalRotation(0.0f, 0.0f, 180.0f); // any initial rotation you want
FVector NewOfs = DesiredLocalRotation.RotateVector(SocketTrans.GetLocation());
MyActorB->SetActorRelativeRotation(DesiredLocalRotation);
MyActorB->SetActorRelativeLocation(NewOfs);

```

Note in your example you rotated ‘B’ 180 degrees, so I added that into my code, but it can be any rotation.
