Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save romainPechot/f717abaf5bbbd3eaa4a6 to your computer and use it in GitHub Desktop.
Save romainPechot/f717abaf5bbbd3eaa4a6 to your computer and use it in GitHub Desktop.
MenuItem for quick copy/paste a Transform hierarchy inside a Unity Scene
using UnityEngine;
using UnityEditor;
public static class MenuItemTransformHierarchyFindPath
{
[MenuItem("CONTEXT/Transform/Copy Transform Path")]
private static void CopySelectionPath(MenuCommand cmd)
{
if(cmd.context)
{
Transform transform = (Transform)cmd.context;
string path = GetTransformPath(transform, string.Empty);
EditorGUIUtility.systemCopyBuffer = path;
Debug.Log("Copy path \"" + path + "\" to clipboard.");
}
}// CopySelectionPath()
private static string GetTransformPath(Transform transform, string path)
{
if(transform)
{
path = transform.name + path;
if(transform.parent)
{
path = "/" + path;
}
return GetTransformPath(transform.parent, path);
}
else return path;
}// GetTransformPath()
}// MenuItemHierarchyFindPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment