godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.37k stars 21.26k forks source link

Godot node referencing problems #98591

Open Udargabi opened 4 weeks ago

Udargabi commented 4 weeks ago

Tested versions

godot 4.3-stable

System information

windows 10, 32 gb ram

Issue description

There are countless times when i wish to reference a node via any method ( $ / % / get_node etc) and godot just returns that the instance is null. After some testing i saw that none of the scene tree was loaded at the call of the _ready() function. This just makes me sad. The first time i noticed this was when i tried to get a timer node.

Steps to reproduce

I create a new scene usualy imbricated in other scenes(2-3 times) and i see results like this. In a scrip try to reference it and here you have the error.

Minimal reproduction project (MRP)

It isn`t constant

OffsetMOSFET commented 4 weeks ago

My behavior has been consistent, personally.

You mentioned using instanced scenes. I know unique (%) node names are only visible in the scene the script is from, so I've had to replace the unique names with @export. Maybe this is what you're experiencing?

shahriarlabib000 commented 3 weeks ago

Awaiting for a single frame in _ready() might be helpful. See: https://forum.godotengine.org/t/why-add-child-funtion-not-work-when-i-used-it-in-ready-functon/69396/8

Edit: Or maybe it's not a good idea if you are calling the var that stores the reference continuously in _process or _physics_process 🤔

Does using @onready var also cause this issue?

Edit2: I just assumed you are storing the reference in a var in _ready. Could you provide some example code of what you are doing in _ready