Acquiring a Bone Socket Location

Hey Community,

It appears that the links in this thread are no longer available. I was wondering if anybody had the documentation or perhaps knows the answer?

If I made a Socket in Pelvis named “Pelv_Socket” then how could I find the location of that socket? Thanks in advance.

How can I find the location of a socket through c++? - Character & Animation - Unreal Engine Forums

This is starting to get a little bit silly…I keep asking these questions and then I find the answers shortly afterwards. Oh well it should be a good reference to anybody else looking.

Anyways if someone could still find the documentation that would be super.

bool socketLocation = Mesh.Get()->DoesSocketExist(“Arg!”);

	if (socketLocation)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::White, FString::FString("This Socket Exists"));
	}

	else
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Cyan, FString::FString("This Socket does not Exist"));
	}

I eventually found it by looking in the API docs.

Keep in mind though, if you get deep into messing with Skeletal Controls or Animation nodes, and etc, this will be a frame late because this transform gets updated after the animation graph is done being evaluated.

To acquire the transform inside the animation graph I’ve been copying this code snippet around for now until there’s a better way:

//code is based off the get socket transform code in skeletal mesh component, only that doesn't work here since it's a frame late, I think.  We must use the FA2CSPose object.
		//I wonder if it's possible to refactor this somehow eventually so the code can be reused
		//get the offset socket's transform relative to the end bone
		{
			int32 BoneIndex = SkelComp->GetBoneIndex(EffectorOffsetSocketName);

			if (BoneIndex != INDEX_NONE)
			{
				OffsetSocketRelativeTransform = MeshBases.GetComponentSpaceTransform(BoneIndex).GetRelativeTransform(EndBoneCSTransform);
			}
			else
			{
				USkeletalMeshSocket const* const Socket = SkelComp->GetSocketByName(EffectorOffsetSocketName);
				BoneIndex = SkelComp->GetBoneIndex(Socket->BoneName);

				if (Socket && BoneIndex != INDEX_NONE)
				{
					OffsetSocketRelativeTransform = (Socket->GetSocketLocalTransform() * MeshBases.GetComponentSpaceTransform(BoneIndex)).GetRelativeTransform(EndBoneCSTransform);
				}
			}
		}

Thanks I appreciate this!

Do you think it would be possible to stick your method into a blueprint-callable function? Like “GetModifiedSocketTransform/Location/Etc”?

It’s possible you may be able to create an anim graph node that extracts the value and returns it in an out param, and then you use that value in a later anim graph node. I’d have to check.

This code is only useful in the context of an anim graph though since it works specifically on the data of the skeletal transforms during the anim graph updating phase.

In any other context you’d want to just use the normal get socket transform functions. If you have something that ends up being a frame late, you’ll have to find a way to make it update during the animation phase, like by attaching it to a socket.