Nodes in Current Scene not loading

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

I have nodes within a scene that I have referenced through onready vars. From my understanding using the onready keyword is effectively the same as initializing the variable within the _ready() function. To my knowledge, in the tree load in tree order then once all nodes are loaded the _ready() function of the main node in the tree runs. I do not understand how the nodes are not being found if this is the case given the screenshot here:

I assume the script in the screenshot is intended to be connected to the top-level GameHandler node, but are you sure that’s the case? I see other nodes in the scene tree with attached scripts…

Assuming the above script is attached to the top-level node, are you sure it’s not unintentionally attached to other node(s) too?

On the surface, I’d expect the code to work as you intend if the script is attached to the top-level node (and only to that node)…

jgodfrey | 2020-10-25 16:12

The selected script is for GameHandler which is attached only to the GameHandler node. Originally I had Map as an instanced scene but I made it a whole part of the GameHandler trying to fix this.

Edit: Also I was originally using the “$” syntax to grab these nodes, which also in the editor finds these nodes. That’s what bothers me the most is that it shows me it can see the nodes in the hierarchy but it isn’t finding them at runtime.

Edit2: Even running the scene independently (Instead of the main scene) causes this behavior.

sHerrmann | 2020-10-25 18:50

Is it possible to make the project available for review?

jgodfrey | 2020-10-25 19:01

Here’s a link to the zip.

Edit: There’s probably some things not working as intended or not implemented yet because I was working through a couple of systems. This just doesn’t make sense as to why the onready nodes aren’t there at runtime.

sHerrmann | 2020-10-25 19:05

That link leads to a 404 (page not found)

jgodfrey | 2020-10-25 19:13

Updated original link as well.

sHerrmann | 2020-10-25 19:14

:bust_in_silhouette: Reply From: jgodfrey

OK, so based on the above discussion and the linked project…

You do indeed have a 2nd copy of GameHandler.gd (incorrectly) linked to a node. That’s what’s causing the problem…

If you look at GameHandler_HUD --> ActionBarButton2, you’ll see it’s connected to the GameHandler.gd script. Looking at the other buttons, it looks like it is supposed to be connected to ActionBarButton.gd.

That’s 100% it. I have no idea how that happened. Thanks. Is there a way to trace the node this script is running from? I’m newer to using Godot so I’m not very familiar.

sHerrmann | 2020-10-25 21:04

Good question. I found it by adding the following to the _ready() function…

print(name)

The results showed 2 things:

  • A node name was printed twice, indicating it was connected to 2 nodes
  • One node name was expected and one was not…

jgodfrey | 2020-10-25 21:12