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

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.

          cybereality Argh, vocabulary, complete misunderstanding again, I'm not talking about the interface within my own project but Godot's interface.

            cybereality Okay, I think I'm starting to get you.

            Did I set this up correctly?

            Also, I've got the proper syntax I'm thinking of now:

            https://docs.godotengine.org/en/3.1/classes/class_node.html#class-node-method-get-index

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

            get_parent().name

            Wish I had found this sooner then I would have made way more sense, so what I'm thinking of would be your label idea but with get.index() and then get_parent().name as the result and as it turns out this should be possible.

            Edit: You mentioned this earlier in the chat and I hadn't double checked, sorry about that.

              Yes, you can do that. But you don't want a Control in a 3D game, unless you intend to display a HUD. What you want to is to right-click the Control, click Change Type, choose Spatial, then in the script, change the second line to read:

              extends Spatial

              You don't have to edit anything else. But you probably need to save everything and then close the editor and reopen this (you only need to do this the first time once). Then click the eye icon to the right of the name of that node to refresh the names after you do something.

              In Object of type 'Spatial': Attempt to connect nonexistent signal 'hide' to method 'Spatial.update_numbers'.

              Sorry, it should be like this:

              tool
              extends Spatial
              
              func _ready():
              	connect("visibility_changed", 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

                cybereality It's doing stuff now, but this is how it's showing up for me. Is it because I'm 3D and you're 2D?

                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)

                  cybereality Same problem unfortunately, also hiding the spatial now seems to crash the engine.