How to Copy Bone Rotation in Unity?
In Unity, you can efficiently copy bone rotation from one bone to another directly within the editor by utilizing the Transform component's properties. This manual method allows for precise transfer of rotational data between game objects representing bones.
Manually Copying Bone Rotation in Unity
The most straightforward way to copy bone rotation involves using Unity's Inspector window to copy and paste the Transform
component's rotation values. This is particularly useful for character rigging adjustments, pose mirroring, or transferring specific orientations between similar bone structures.
Step-by-Step Guide
Follow these steps to copy and paste bone rotation:
-
Locate the Bone Structure:
- Open your Unity project and navigate to the
Hierarchy
window. - Find the
GameObject
representing your character model or skeletal rig. - Expand the hierarchy to reveal the individual
GameObjects
that act as bones (e.g.,Hips
,Spine
,UpperArm
,LowerArm
,Hand
).
- Open your Unity project and navigate to the
-
Select the Source Bone:
- In the
Hierarchy
window, select the source bone – theGameObject
whose rotation you wish to copy.
- In the
-
Copy Rotation Values:
- With the source bone selected, observe its
Transform
component in theInspector
window. - Locate the Rotation property within the
Transform
component. - Right-click directly on the "Rotation" label itself.
- From the context menu that appears, select
Copy Property
(orCopy Value
, depending on Unity version and context) to copy the entire rotation vector (X, Y, Z, and W for Quaternions internally). - Alternatively, you can manually select and copy the individual X, Y, Z values if viewing in Euler angles.
- With the source bone selected, observe its
-
Select the Target Bone:
- In the
Hierarchy
window, select the target bone – theGameObject
where you want to apply the copied rotation.
- In the
-
Paste Rotation Values:
- With the target bone selected, go to its
Transform
component in theInspector
window. - Locate the Rotation property.
- Right-click on the "Rotation" label.
- From the context menu, select
Paste Property
(orPaste Value
). This action will replace the target bone's current rotation with the copied values from the source bone.
- With the target bone selected, go to its
For more information on the Transform component, refer to the official Unity Transform documentation.
Important Considerations
When copying bone rotation, keep the following in mind:
- Local vs. World Rotation: The values displayed and copied in the Inspector typically represent the local rotation of the bone relative to its parent. Copying these values is generally what you want for transferring bone poses. If you need to match world space rotation, you might need to adjust for parent rotations or use scripting.
- Parent Hierarchy: Even with identical local rotations, bones in different parent hierarchies or with different parent rotations will have different world orientations. Ensure your target bone's parent structure is appropriate for the desired result.
- Animation Overrides: If the bone is part of an animated character, any copied rotation might be overridden by the animation system during play mode unless you specifically disable animation for that bone or update its rotation via a script after animation has applied.
Programmatic Bone Rotation Copying
For scenarios requiring dynamic or runtime bone rotation transfer, especially in complex character setups or procedural animations, scripting offers a robust solution:
-
C# Scripting: You can access the
transform.rotation
(world rotation) ortransform.localRotation
(local rotation) property of a source bone and assign it to the corresponding property of a target bone within a C# script. This is often done inLateUpdate()
to ensure it applies after animation updates.// Example C# code snippet public Transform sourceBone; public Transform targetBone; void LateUpdate() { if (sourceBone != null && targetBone != null) { // Copy local rotation targetBone.localRotation = sourceBone.localRotation; // Or copy world rotation (less common for individual bone adjustments) // targetBone.rotation = sourceBone.rotation; } }
-
Animation Tools: For more advanced animation retargeting or mirroring, Unity's built-in Humanoid Rig Setup and various third-party animation tools provide dedicated features to copy, mirror, and remap bone rotations across different characters or rigs.