Skip to content

Instantly share code, notes, and snippets.

@marcosecchi
Created June 15, 2016 12:54
Show Gist options
  • Save marcosecchi/e8dc19f27c9ab48bc490cb444488d8e6 to your computer and use it in GitHub Desktop.
Save marcosecchi/e8dc19f27c9ab48bc490cb444488d8e6 to your computer and use it in GitHub Desktop.
Returns the full hierarchy name of the game object in Unity3D
using UnityEngine;
public static class GameObjectExtensions {
/// <summary>
/// Returns the full hierarchy name of the game object.
/// </summary>
/// <param name="go">The game object.</param>
public static string GetFullName (this GameObject go) {
string name = go.name;
while (go.transform.parent != null) {
go = go.transform.parent.gameObject;
name = go.name + "/" + name;
}
return name;
}
}
@bawahakim
Copy link

Works beautifully, thank you!

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