Node not found. Yet it was working recently

Godot Version

4.2.2

Question

In the pig.gd I use:

@onready var player = %Player
@onready var game_manager = %game_manager

but get “Node not found” for both of them.

Screenshot 2024-05-07 at 22.42.42

What’s weird:

  1. in the same file (pig.gd) I use some other uniquely named nodes, and they work fine:
@onready var walk_timer = %WalkTimer
@onready var eat_timer = %EatTimer
  1. I have the @onready var game_manager = %game_manager in the food.gd. it works fine there.
  2. For testing purposes I added @onready var player = %Player and @onready var game_manager = %game_manager to the red_ninja.gd and it works fine.
  3. What’s even more weird is that like half a day ago this exact variables (%Player and %game_manager) were working fine in the pig.gd (the file I currently have troubles with), and now they don’t work.

Using @onready var game_manager = $"../game_manager" and @onready var player = $"../player" works, but…

I don’t want to access the node using hardcoded path like ones I just mentioned or using get_node() and still hard coding it with something like root or get_parent() or whatever.

I don’t have a clue why that is happening, seems like a bug, but maybe I’m missing something.

If someone has an idea why it doesn’t work or how to fix it — please share.

Thanks in advance.

Try put the Pig node above the game_manager node and see if works

I’ve tried it before and I tried it now, unfortunately it doesn’t help.

It is misleading, the unique names with % only apply to that scene. pig.gd shouldn’t be able to see parent unique names, or sibiling unique names. If you do not want hard coded paths maybe @export will work better for pig and red ninja, or using Autoloads for game_manager.gd

1 Like

@gertkeno Is right, i took a look on unique node docs and has this limitation. As was already said you can use autoloads, another option is use groups.

Scene Unique Nodes — Godot Engine (stable) documentation in English

2 Likes

I tried @export, it works, so I can call it a solution. I’ll also check the Autoloads and then decide what fits best.

I guess the limitations for using unique names with sibling nodes are not well implemented in the engine, and the real bug is in the fact that I can use % with some sibling nodes.

1 Like