Skip to content

Instantly share code, notes, and snippets.

@RoxDevvv
Created May 9, 2025 09:45
Show Gist options
  • Save RoxDevvv/b810d99ee11d148ac70bfaf767726a95 to your computer and use it in GitHub Desktop.
Save RoxDevvv/b810d99ee11d148ac70bfaf767726a95 to your computer and use it in GitHub Desktop.
Copy World Transform Hierarchy (Unity Editor Tool)
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));
}
}
}
@RoxDevvv
Copy link
Author

RoxDevvv commented May 9, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment