i am trying to build hierarchy from object that has a lot of subobjects in a way that i get this displayed:
"main object > object1 > subobject2"
where all parts act as links, when clicked that object gets selected.
how to do that?
i am trying to build hierarchy from object that has a lot of subobjects in a way that i get this displayed:
"main object > object1 > subobject2"
where all parts act as links, when clicked that object gets selected.
how to do that?
ok, i see that there are no “links” in unity and the way i could simulate them is to get the names of hierarchy relationships between objects and make buttons that will select the object they represent when clicked.
so basically if i have this structure or hierarchy
main object
object1
subobject1
subobject2
object2
subobject1
subobject2
subobject3
object3
subobject1
subobject2
subobject3
and i have this object selected main object/object2/subobject1 i would like to have similiar representation with buttons like this:
button(main object)->button(object2)->button(subobject1)
so when i click any of these buttons in the hierarchy i get object or group of objects selected.
any ideas how to construct the path if i have one object selected in the hierachy? i tried something like this:
var parent : Transform = cam.currentTarget.parent;
for(var child : Transform in parent){
Debug.Log("Child: " + child.name);
for(var c in child){
Debug.Log("Sub-child: " + c.name);
}
}
this will print all objects in that hierarchy, from the parent of the selection to the end.
i would like to have path from the root to the selected object, i dont know how to get it
any ideas?
This kind of thing is typically handled using a recursive function (ie, a function that calls itself):-
function ShowHierarchy(rootTrans: Transform, spaces: String) {
print(spaces + rootTrans.name);
for (child in rootTrans) {
ShowHierarchy(child, spaces + " ");
}
}
i tried what you proposed, in fact i tried your script, where rootTrans is the transform of the root of hierarchy… and it displays entire tree.
i guess that maybe i am not using it correctly, basically your function even doesn’t know what object is currently selected.
so if i have this tree
ROOT
object A
object AA
object B
object Ba
object C
object CA
object CA-1 (this object is selected)
and i have object CA-1 selected (and can get it its
transform) how to get this displayed:
ROOT->object C->object CA->object CA-1
to get the “path” of the object…
any help appreciated.