How can I get a gameobject scene path,and where "scene path" come from in gameobject watch panel?

I want to get a gameobject scene path, like “PromptDialog/Content/Widnow/BtnClose”, except by enum parent, how can i do that?

I found there’s a “Scene path” in watch panel, but I can’t find where it come from? amazing! (Components, Children, Scene path where are they come from?)

The icon next to those three entries stands for “Constant”. They can’t be actual constants in C# but they’re not normal properties that you could access from code. They’re likely synthesized in Unity’s debugger adapter and marked constant because you cannot change their value in the debugger.

To get the components, you can use GetComponents<Component>(), and to get the children, you can iterate over a Transform (see the example in the documentation) or use Transform.GetChild. I don’t think there’s anything built-in to construct a scene path but you can do that yourself by recursing through all Transform.parent.

thanks for your advice

  private static string GetInScenePath(Transform transform)
        {
            var current = transform;
            var inScenePath = new List<string> { current.name };
            while (current != transform.root)
            {
                current = current.parent;
                inScenePath.Add(current.name);
            }
            var sb = new StringBuilder();
            foreach (var item in Enumerable.Reverse(inScenePath)) sb.Append($"\\{item}");
            return sb.ToString().TrimStart('\\');
        }