get_children() returns empty array despite children existing.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By druidpeter

I have a node setup such that a parent node, “WranglePool” contains a bunch of Mesh Instance nodes as children. 56 to be exact.

Now, whenever a signal, “recalibrate_triggered” is triggered, “WranglePool” needs to iterate over it’s children, and determine the distance of each mesh from a specific location given as a parameter.

Here’s the issue: Even though there’s 56 children in the editor, and there’s 56 children in the inspector, when actually debugging at runtime, the “subordinates” variable, which is SUPPOSED to contain the array of children returned by self.get_children()… is simply empty.

  1. Some things to note: I have tried using “self.get_children()” at runtime during the handling of the signal itself.
  2. I have ensured that “subordinates = self.get_children()” is called inside the _ready() function of the WranglePool script, which means that all the mesh nodes SHOULD be loaded when the method is called, right?
  3. The first time the “recalibrate_triggered” signal is emitted is during the “Overworld” node’s “_ready()” function. The Overworld node is the root node of the entire level worldspace, so EVERYTHING should be loaded when this signal is emitted.

I am at a loss as to what is going on here. Does anyone have any potential insight? I am using Godot Version 3.5, and do not wish to upgrade to version 4.0 due to incompatibility issues, though of course if this turns out to be some sort of bug in the editor itself then… well, I’ll upgrade if necessary.

But if there’s anything else I might have missed that can help solve this, that would be wonderful. Thank you.

I’m curious if this is timing related. To check, maybe add a simple button to your scene that, when pressed, runs your get_children() code. By the time you press the button, everything should definitely be loaded and available. Does it work as expected then?

While not an answer, it might shed some light on the problem…

jgodfrey | 2023-06-22 01:52