Home / Forums / Skeleton / Bone ESP in Unity Games using Animator.GetBoneTransform

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

Skeleton / Bone ESP in Unity Games using Animator.GetBoneTransform

BoneMatrix_
CS2 & Skeleton Math
MEMBER
Rep: 190
Join Date: Aug 2024
Posts: 21
Thanks: 47
2y ago · Mar 16, 2024 1:40 PM
#1
Most humanoid characters in Unity games utilize Unity's built-in
CSHARP
Animator
component and
CSHARP
HumanBodyBones
enum.

How to read and connect skeletal joints in Unity C#:
CSHARP
using UnityEngine;

public static class SkeletonESP
{
    private static readonly (HumanBodyBones, HumanBodyBones)[] BoneConnections = new[]
    {
        // Spine & Head
        (HumanBodyBones.Head, HumanBodyBones.Neck),
        (HumanBodyBones.Neck, HumanBodyBones.Chest),
        (HumanBodyBones.Chest, HumanBodyBones.Spine),
        (HumanBodyBones.Spine, HumanBodyBones.Hips),

        // Left Arm
        (HumanBodyBones.Chest, HumanBodyBones.LeftShoulder),
        (HumanBodyBones.LeftShoulder, HumanBodyBones.LeftUpperArm),
        (HumanBodyBones.LeftUpperArm, HumanBodyBones.LeftLowerArm),
        (HumanBodyBones.LeftLowerArm, HumanBodyBones.LeftHand),

        // Right Arm
        (HumanBodyBones.Chest, HumanBodyBones.RightShoulder),
        (HumanBodyBones.RightShoulder, HumanBodyBones.RightUpperArm),
        (HumanBodyBones.RightUpperArm, HumanBodyBones.RightLowerArm),
        (HumanBodyBones.RightLowerArm, HumanBodyBones.RightHand),

        // Left Leg
        (HumanBodyBones.Hips, HumanBodyBones.LeftUpperLeg),
        (HumanBodyBones.LeftUpperLeg, HumanBodyBones.LeftLowerLeg),
        (HumanBodyBones.LeftLowerLeg, HumanBodyBones.LeftFoot),

        // Right Leg
        (HumanBodyBones.Hips, HumanBodyBones.RightUpperLeg),
        (HumanBodyBones.RightUpperLeg, HumanBodyBones.RightLowerLeg),
        (HumanBodyBones.RightLowerLeg, HumanBodyBones.RightFoot)
    };

    public static void DrawSkeleton(Animator animator, Camera camera, Color boneColor)
    {
        if (animator == null || !animator.isHuman) return;

        foreach (var (boneA, boneB) in BoneConnections)
        {
            Transform tA = animator.GetBoneTransform(boneA);
            Transform tB = animator.GetBoneTransform(boneB);
            if (tA == null || tB == null) continue;

            Vector3 sA = camera.WorldToScreenPoint(tA.position);
            Vector3 sB = camera.WorldToScreenPoint(tB.position);
            if (sA.z <= 0.01f || sB.z <= 0.01f) continue;

            Vector2 screenA = new Vector2(sA.x, Screen.height - sA.y);
            Vector2 screenB = new Vector2(sB.x, Screen.height - sB.y);

            // Draw line between joint A and joint B
            DrawLine(screenA, screenB, boneColor);
        }
    }
}
BoneMatrix_ · Source 2 Skeleton ESP & Hitboxes
The following users thanked BoneMatrix_ for this post:
IL2Cpp_Wizard
IL2Cpp & Metadata Engineer
VIP
Rep: 360
Join Date: Feb 2023
Posts: 21
Thanks: 92
2y ago · Mar 16, 2024 4:10 PM
#2
If the game uses a non-humanoid generic rig or custom ragdoll bones, you can iterate through the
CSHARP
SkinnedMeshRenderer.bones
transform array or find bones by common hierarchy names (e.g.
CODE
Bip01_Head
,
CODE
mixamorig:Head
).
IL2Cpp_Wizard · Il2CppInspector & Ghidra / IDA Integration
Reconstructing C# type descriptors & GameAssembly.dll offsets
VectorByte
Graphics & DirectX Dev
VIP
Rep: 420
Join Date: Aug 2022
Posts: 39
Thanks: 115
2y ago · Mar 17, 2024 9:40 AM
#3
Skeleton ESP is so responsive compared to fixed boxes because it tracks actual player animations like jumping, leaning, or reloading in real time.
VectorByte | DirectX 11/12 Hooking & ImGui Overlays
Quote
Math is the language of game engines.