Created
May 9, 2025 09:45
-
-
Save RoxDevvv/b810d99ee11d148ac70bfaf767726a95 to your computer and use it in GitHub Desktop.
Copy World Transform Hierarchy (Unity Editor Tool)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEngine; | |
public class WorldTransformCopier : MonoBehaviour | |
{ | |
[MenuItem("Auto/Copy World Transform Hierarchy %#c")] | |
static void CopyHierarchy() | |
{ | |
if (Selection.gameObjects.Length != 2) | |
{ | |
Debug.LogError("Select exactly TWO GameObjects: first the source, then the target."); | |
return; | |
} | |
Transform source = Selection.gameObjects[0].transform; | |
Transform target = Selection.gameObjects[1].transform; | |
CopyWorldTransformRecursive(source, target); | |
Debug.Log("Copied WORLD transform hierarchy."); | |
} | |
static void CopyWorldTransformRecursive(Transform source, Transform target) | |
{ | |
target.SetPositionAndRotation(source.position, source.rotation); | |
for (int i = 0; i < Mathf.Min(source.childCount, target.childCount); i++) | |
{ | |
CopyWorldTransformRecursive(source.GetChild(i), target.GetChild(i)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Copy World Transform Hierarchy (Unity Editor Tool)
A simple Unity Editor script that copies the world position, rotation from one GameObject hierarchy to another with the same structure. Useful for syncing poses or placements between matching rigs or prefab instances.