Node not found

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

The line is question is this one

$Camera2D/HUD/HUDLayer/Ammo.text = str(Global.ammo) + "/" + str(Global.max_ammo)

and it has the error

Invalid set index 'text' (on base: 'null instance') with value of type 'String'.

with a secondary error of

get_node: Node not found: HUDLayer/Ammo

the even stranger part of this was it just broke randomly and I was never having a problem with it before, the code seems to be completely correct even by checking other errors like this on other questions it is usually that they spelt something wrong or missed capitalization which is not the problem

node structure
Camera2D/HUD/HUDLayer/Ammo

Is Camera2D the node the script is on? If so, it shouldn’t be in the node path.

exuin | 2021-02-18 16:07

Oh no sorry the root node is what the script is on if forgot to add the camera node to the text as I was making changes and then undid them

Shazelz | 2021-02-18 16:32

:bust_in_silhouette: Reply From: Lopy

You only really have one issue of your $ not working, the other one is a byproduct.

Try to call print_tree(), or print_tree_pretty(), just before the $. This will show you what is actually happening.

Possible reasons why $/get_node() would fail:

  • Called inside an _init() instead of a _ready().
  • A Node was removed in code using queue_free or remove_child.
  • Names/paths do not exactly match.
  • A Node was renamed automatically to guaranty the uniqueness of names among siblings.
  • The script was put on another Node by accident, with ill-named children.