Class SkeletonBinder
Utility for binding equipment SkinnedMeshRenderers to the character skeleton at runtime. Provides safe bone binding that does not destroy shared parent hierarchies.
public static class SkeletonBinder
- Inheritance
-
SkeletonBinder
- Inherited Members
Methods
BindMesh(SkinnedMeshRenderer, Transform)
Binds a SkinnedMeshRenderer to the target skeleton. Matches the renderer's bone names to transforms in the skeleton hierarchy, assigns rootBone and bones, and reparents the renderer under the skeleton root.
WARNING: This destroys the renderer's current parent GameObject. Only use when the parent is a disposable wrapper (e.g., loading a standalone equipment prefab). For pooled equipment renderers, use BindMeshKeepParent(SkinnedMeshRenderer, Transform) instead.
public static void BindMesh(SkinnedMeshRenderer renderer, Transform skeletonRoot)
Parameters
rendererSkinnedMeshRendererThe equipment SkinnedMeshRenderer to bind.
skeletonRootTransformThe root Transform of the character skeleton.
BindMeshKeepParent(SkinnedMeshRenderer, Transform)
Binds a SkinnedMeshRenderer's bones to the target skeleton WITHOUT reparenting or destroying the current parent. Safe for pooled equipment renderers that share a common parent (e.g., EquipmentRoot).
Performs only the bone name matching and assignment of rootBone/bones. The renderer stays in its original position in the hierarchy.
public static bool BindMeshKeepParent(SkinnedMeshRenderer renderer, Transform skeletonRoot)
Parameters
rendererSkinnedMeshRendererThe equipment SkinnedMeshRenderer to bind.
skeletonRootTransformThe root Transform of the character skeleton.
Returns
- bool
True if all bones were matched successfully.
ClearBoneCache(Transform)
Invalidates all bone caches. Call when a character is destroyed or models are swapped. Increments the generation counter so all existing cache entries are invalidated.
public static void ClearBoneCache(Transform skeletonRoot = null)
Parameters
skeletonRootTransformThe skeleton root whose cache to clear, or null to invalidate all caches globally.
GetBoneTransform(Transform, string)
Finds a bone Transform by name within the skeleton hierarchy. Results are cached per skeleton root instance for performance. Uses a generation counter to prevent stale Transform references from Unity instance ID recycling.
public static Transform GetBoneTransform(Transform skeletonRoot, string boneName)
Parameters
skeletonRootTransformThe root Transform of the character skeleton.
boneNamestringThe exact bone name to find.
Returns
- Transform
The bone Transform, or null if not found.