Trouble accessing instance of child node's child's properties?

Godot Version



My program creates a turn order for players. Each member block contains their name and their current delay count that ticks with time until 0, and then it’s their turn (similar to Trails series). The member block is a scene, and the important node is Member → Color Rect → Color Rect → SpinBox, which holds the value of the delay.

The parent node creates instances of each member scene. I’m trying to write a function that will organize the child nodes so that the lowest value is on top when the turn order is displayed (below).

I get an error on the “if get_child(minimumIndex)” line, and it says “Invalid get index ‘value’ (on base: ‘null instance’)” The Errors tab also says “Node not Found.”

I’m not sure what I’m doing wrong, though it’s probably obvious to someone more familiar. In another function, I preload the scene, but I was under the impression that I would only need to do that once for the whole program? Any help is appreciated, since the only programming I’ve done before this was on assignments in class.

Tangential question: does move_child insert the child node at the given index, and push the other child nodes up an index, or does it swap the child with whatever node was there?

If I need to provide more info, please ask.

func memberSort():
	if get_child_count() == 0:
	var childCount = get_child_count()+1
	for i in childCount:
		var minimumIndex = i
		for j in range(i+1, childCount):
			if get_child(minimumIndex).get_node("$ColorRect/ColorRect/SpinBox").value < get_child(j).get_node("$ColorRect/ColorRect/SpinBox").value:
				minimumIndex = j
			if (i != minimumIndex):
				swapMember(i, minimumIndex)

That’s telling you that your ‘self’ is null. What is your script extending?

Extends Color Rect

I actually hadn’t considered that. Is the Extends keyword similar to importing libraries in C++?

Its not self that is null, it is $ColorRect/ColorRect/SpinBox that is returning null.

1 Like


The ‘$’ is GDScript shorthand for get_node().
It doesn’t belong in the string.
Try changing it to:

if get_child(minimumIndex).get_node("ColorRect/ColorRect/SpinBox").value   

I don’t have access to your tree so the above line might need to be rejigged to satisfy node path rules.

Actually the path you use in that string is easiest placed if you grab the node from the tree and drag it into the code area.

Thank you for the help. I had actually tried that earlier and it wasn’t working. After removing the “+1” on get_child_count() along with your advice, though, the program is at least not throwing an error. I just need to make the swap function work now lol.

Depending on how you are doing it swap may not work.
Although objects are passed by reference, as soon as you assign it to something else it will break the connection.
See this post here.
(and make sure you read the last post that corrects an error I made in the thread)