Node Reference doesn't work

Godot Version

<4.2.2>

Question

<reference of CharacterBody2D doesn’t work. i drag it from scene, press control, so reference should be correct. (code 1-3) but it says it’s null!(4) and it degub it prints Node %ryuji not found. script is attached to inventory. the structure is like “root/node/scene_icons/inventory” the weirdest thing, in the same scene i have object with the same realisation, that works (5)>


изображение

изображение

Where’s _on_use_pressed?
Try to print ryuji at the first line of _ready.

it prints <Object#null>

_on_use_pressed is from USE button.
изображение

You should use %ryuji in the script of Node(first capture, root node), not other place.
If can’t, you should use singleton:

  • You can add Singleton.property = self in _ready of ryuji node.
  • You can also attach a script to Node and add Singleton.property = %ryuji in _ready of Node.

(edit)It’s not only can use singleton, static variable can works too.

1 Like

could you tell what is a singleton? and static variables? or where to read on it

And static variable is like normal variable, but it’s binded to type(such as Node, CustomClass), not object.
Define: static var <variable_name>[: <type>][ = <value>]
Usage: <Type>.<variable_name> <Type>.<variable.name> = <value>

1 Like

thanks everyone who replied here, but i found a rather cool solution by just manually going through nodes (or using get_node()). if anyone has the same problem, i would be glad if it helps
изображение

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.