Var declared with onready works sometimes, not others - returns null

I agree with your debugging stance - I’ve had to deal with it as the vendor for many years.

Regarding the assignments - also yes. It never occurred to me that the path would not be correct. I’ve only used ctrl-drag/drop for my @onready vars. But this is also my first Godot project and I’m still acclimating to the coding rules.

Nevertheless, I now have another thing to check when there’s an error.

It would have been nice to get a better error message from the start. The later messages were more informative when they mentioned the path.

Live and learn!

Well, I spoke too soon - the problem is not resolved.

I was continuing some work and then had the same Error that started this thread.
Needless to say I was not pleased.

I did some testing and here are the results:

# The short (no full path) slot_grid onready below works everywhere if InventoryMain node is 'editable children'
# If InventoryMain is not 'editable children' then fails in func add_item_to_slot
@onready var slot_grid: GridContainer = $VBoxContainer/ScrollContainer/SlotGrid


# This fails in build_slots if InventoryMain is 'editable children' or not
#@onready var slot_grid: GridContainer = $"/root/InventoryMain/InventoryGrid/VBoxContainer/ScrollContainer/SlotGrid"

# Won't work if InventoryMain  is NOT 'editable children' with either onready

FYI - I also tried doing this, but it made no difference:

func _ready() -> void:
     call_deferred("build_slots")

This is really driving me crazy.
Why would a reference to a node in an Instantiated scene fail to be reachable if the node is not in ‘editable children’ mode?
It seems like accessing a ‘collapsed’ instantiated scene node should be normal behavior.

Can you make and post a minimal reproduction project?

The whole project is only 148k zipped - how about that?

How can I upload here?

You can’t. You need to host is elsewhere and post the link.

However, it’d be better to replicate it by minimal means in a fresh project. It’s much easier for people to help you when the problem is isolated, and the process of doing so may reveal to you where the problem actually is.

Same issues - worse, in fact. Now I get the error regardless of the onready statement or ‘editable children’…

test_proj

The link is not accessible.

Sorry - forgot to share - try now

That’s not really minimal.

It’s as minimal as I could make it while still trying to access the necessary nodes.

If you meant make a blank hierarchy of similar nodes, I’m not sure that would help.

Did you mean something else?

The idea of the minimal project is to re-create the problem from scratch.

Are you able to test with what I sent?

Does your global scene have any nodes? Did you add the script .gd as a global or the scene .tscn? If you only added the script, then it will not have any children.

if you look at the OP, you’ll see screenshots showing the scene “InventoryManager” in the tree.

Is that what you are referring to?