GetSocketByName() nullptr [C++]

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!

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 ! :slight_smile:
Have a good day !

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!

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 ^^

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

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.