• QuestionCommunity
  • Is there a way on the interface to check your parents and children at a glance?

Something I've been realising about my workflow is often when it comes to Godot and when I was working with Unity actually I'm constantly fiddling around with even figuring out whether or not a node is parented correctly or what index a child is on within the hierarchy of a parent. Is there some kind of option for index debugging? Or is this not on Godot? If so I would post it as a feature request because it would save so much time.

Before I waste anyone's time, by the way I am aware of the grey lines and what they represent, I'd like to have more detailed information on the index itself available. Another thing that would be nice too would be able to quickly check without what child is parented to on the interface.

    • [deleted]

    • Best Answerset by Lethn

    I should have tested more. This should work.

    tool
    extends Spatial
    
    func _ready():
    	connect("visibility_changed", self, "update_numbers")
    	
    func update_numbers():
    	if Engine.editor_hint:
    		if not visible:
    			number_children(self)
    		else:
    			clear_children(self)
    	
    func number_children(node):
    	var title = node.name
    	var idx = title.find("-")
    	if idx > 0:
    		title = title.substr(idx + 2)
    	node.name = str(node.get_index()) + " - " + title
    	for child in node.get_children():
    		number_children(child)
    		
    func clear_children(node):
    	var title = node.name
    	var idx = title.find("-")
    	if idx > 0:
    		title = title.substr(idx + 2)
    	node.name = title
    	for child in node.get_children():
    		clear_children(child)

Are we talking 2D or 3D? Draw order is essentially determines by the nodes order in the scene tree/hierarchy.

    Megalomaniak No no, not the draw order, I'm talking about when you use get_child or get_parent so for example in Blender you can easily see on the interface and click a tab to find out what the object is parented to and I was wondering if Godot had that.

    Megalomaniak Is there any way it can be done through the interface though? Seems from what you're telling me it's not possible.

    I mean you can look at the scene tree if you want to see what is the child or what is the parent of something. You can also make instanced scenes temporarily expanded/visible in the scene tree if you need to.

    cybereality LOL yes, I think you guys are misunderstanding me though, is their a way of doing these checks on the interface? I think I need to do a little mockup to show what I mean. It would be nice if you could have the index numbers of the children listed in the actual hierarchy for easy viewing without the code, then you'd know what to reference faster.

    And in Blender you have the relations tab which allows you to view the name of the parent in the hierarchy the child belongs to.

    A typical hierarchy will be small, because you are encouraged to use scenes (and nested scenes) to organize your project. If you do this, you'll only have a couple objects in the tree. You can also temporarily expand or contract scenes if you need to see their children.

    I don't think you can really reference objects by id quite the same way in godot as you can in blender, runtime environments and the object id's in them can be rather, uhh, dynamic. So what you might see in the editor might not correspond with what a node might get as it's id in running game.

    ID's can still be useful of course, but again, you'd need to get them and maybe store in some variant during runtime for it to be useful.

      Megalomaniak Thanks, so if I'm understanding this correctly it's a back end problem on why you can't have the interface potentially setup this way?

      What specifically is the issue? I am not really understanding the workflow.

      Right, the OP is asking for an id number. Let's say it said "37". How would that be easier than looking in the tree?

        cybereality For the record I'm not asking for the ID number of the node globally, I'm talking about the child index.

        Yes, I get it. I just don't see how that helps at all. You can see the name of the node already (which you can name anything you like, even "3 Floor"), shouldn't that be clear enough? I'm not trying to be rude, I really want to understand what you are asking for since it doesn't make sense to me.

          And those child indices are runtime generated in order they are added to the parent. Technically get_children() returns an array so there's a variety of things you can do to it/with it. But for a variety of reasons the editor can't be trusted to give you the same exact order of indices as the runtime I guess.

          https://docs.godotengine.org/en/stable/classes/class_array.html
          https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-get-children

          cybereality It's no biggy, I'm just wondering why there isn't any kind of interface to more quickly check rather than doing a print in code. I just had a moment because I realised how many nodes I often end up working with and sometimes I wonder if it couldn't be easier to keep track of child indexes. Again, I'm purely talking about finding out the relationship of a node, not the unique ID or the name.

          I'm thinking of get_child(0) but having the result of that on the interface which is what the mockup was about on the Godot hierarchy. Normally you would have to do print (get_child(0).name) in the debugger, though in this case I want to see the index int number of the named node in the Godot hierarchy.

          I really don't know how I can explain it in any other way lol.

            It still doesn't make sense, but I decided to code this for you. This should be a script on the root of the scene. You will have to rename the extends to "Spatial" or "Node2D" or whatever the node is in your game. Then just hide and show that root node with the eye icon and numbers will update.

            tool
            extends Control
            
            func _ready():
            	connect("hide", self, "update_numbers")
            	
            func update_numbers():
            	if Engine.editor_hint:
            		number_children(self, 1)
            	
            func number_children(node, num):
            	var title = node.name
            	var idx = title.find("-")
            	if idx > 0:
            		title = title.substr(idx + 2)
            	node.name = str(num) + " - " + title
            	for child in node.get_children():
            		number_children(child, num)
            		num += 1

            Note, the first time you attach the script you may have to close the scene or the editor and open it again, but after that it will just work.