# GetSocketByName() nullptr \[C++\]

**URL:** <https://forums.unrealengine.com/t/getsocketbyname-nullptr-c/409803>\
**Category:** C++\
**Tags:** socket, unreal-engine, skeletalmesh, CPP, question\
**Created:** [November 16, 2017, 3:10pm UTC](https://forums.unrealengine.com/t/getsocketbyname-nullptr-c/409803 "2017-11-16T15:10:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_7fb70ffd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7fb70ffd](https://forums.unrealengine.com/u/anonymous_user_7fb70ffd)\
**Post date:** [November 16, 2017, 3:10pm UTC](https://forums.unrealengine.com/t/getsocketbyname-nullptr-c/409803/1 "2017-11-16T15:10:17Z")

</div>

So, I’m trying to access a bone (or socket) by name.  
I can get it’s position by calling GetSocketLocation(), but when I try to get a USkeletalMeshSocket via GetSocketByName(), I always get a nullptr for the bone with the same name.

```
// This works fine, and returns a correct location
SkeletalMesh->GetSocketLocation("MyBoneName");
// However this always returns nullptr
SkeletalMesh->GetSocketByName("MyBoneName");

```

Is it a bug or I’m doing something wrong here?  
Thanks!

---

<div class="post-metadata">

**Author:** ![Firefly74](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Firefly74](https://forums.unrealengine.com/u/Firefly74)\
**Post date:** [November 16, 2017, 3:43pm UTC](https://forums.unrealengine.com/t/getsocketbyname-nullptr-c/409803/2 "2017-11-16T15:43:52Z")

</div>

Hi !  
Most likely because it’s a bone name and not a socket name

You have to create the socket manually on a bone on your skeletal mesh asset ( right click on a bone =\> add socket )

to get a bone transform you need to do :

```
	int32 boneIndex = GetBoneIndex(boneName);
if (boneIndex != INDEX_NONE)
{
  auto boneTransform = GetBoneTransform(boneIndex);
}

```

Hope this helped you ! 🙂  
Have a good day !

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_7fb70ffd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7fb70ffd](https://forums.unrealengine.com/u/anonymous_user_7fb70ffd)\
**Post date:** [November 16, 2017, 5:19pm UTC](https://forums.unrealengine.com/t/getsocketbyname-nullptr-c/409803/3 "2017-11-16T17:19:17Z")

</div>

Hi, I find it a bit weird that I have to create a “socket” on top of an existing bone. I actually assumed that socket = bone (since naming in UE4 in general is pretty weird). But, anyway, you’re absolutely correct, adding the socket manually fixes the problem! Thanks, cheers!

---

<div class="post-metadata">

**Author:** ![Firefly74](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Firefly74](https://forums.unrealengine.com/u/Firefly74)\
**Post date:** [November 16, 2017, 6:04pm UTC](https://forums.unrealengine.com/t/getsocketbyname-nullptr-c/409803/4 "2017-11-16T18:04:09Z")

</div>

You have to create them manually because socket can have an additional offset on top of the bone.

I think having automatic socket for every bone would make the skeleton tree kinda unreadable and would be an unnecessary overhead. But i agree about naming, sometime it could be better ^^

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_7fb70ffd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_7fb70ffd](https://forums.unrealengine.com/u/anonymous_user_7fb70ffd)\
**Post date:** [November 16, 2017, 9:03pm UTC](https://forums.unrealengine.com/t/getsocketbyname-nullptr-c/409803/5 "2017-11-16T21:03:13Z")

</div>

You seem to have experience with skeletal meshes. I’ve encountered a new issue related to this topic, which, I believe, is a bug this time. I’d appreciate if you’d help me out with it: [C++ GetAllSocketNames returns bones along with sockets - Character & Animation - Epic Developer Community Forums](https://answers.unrealengine.com/questions/726464/c-getallsocketnames-returns-some-bones-and-sockets.html)

---

<div class="post-metadata">

**Author:** ![ali.quaker](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ali.quaker](https://forums.unrealengine.com/u/ali.quaker)\
**Post date:** [February 4, 2021, 1:55pm UTC](https://forums.unrealengine.com/t/getsocketbyname-nullptr-c/409803/6 "2021-02-04T13:55:22Z")

</div>

What I don’t get is that when you call GetMesh()-\>DoesSocketExist(FName(“BoneName”)) with the BoneName it returns true but trying toget the socket returns Nulllptr. This is very confusing and non-intuitive.
