Path seem corret but show not corret

Godot Version

4.3

Question

I have 2 variables that are referencing 2 objects, every time I press play it shows an error that the path is not correct, but I can see that the path is correct, what could be the issue? the error keeps pointing at _ready func. My dialogue box object has the script.

#code
@onready var player = $"../Player"
@onready var ui_prompt = $"ui_container"


func _ready() -> void:
	player.disable_inputs()
	ui_prompt.visible = false  

# errors
dialogue_script.gd:3 @ _ready(): Node not found: "../Player" (relative to "/root/DialogueScript").
  <C++ Error>    Method/function failed. Returning: nullptr
  <C++ Source>   scene/main/node.cpp:1792 @ get_node()
  <Stack Trace>  dialogue_script.gd:3 @ _ready()

  dialogue_script.gd:4 @ _ready(): Node not found: "ui_container" (relative to "/root/DialogueScript").
  <C++ Error>    Method/function failed. Returning: nullptr
  <C++ Source>   scene/main/node.cpp:1792 @ get_node()
  <Stack Trace>  dialogue_script.gd:4 @ _ready()

this is how all my objects are set

During _ready the node tree is not yet completely created. If I remember correctly, you can only safely access nodes, that are children. So I can see two different approaches:

  1. get a reference to the other node after the scene tree has been created
  2. change your approach, so that you don’t access $“…” anywhere

I would recommend the second approach. In the long run it will help you to structure your project more modular and allows you to reuse components more easily.

but this worked before for me, right now i added a dialogue manager asset and had to change some stuff in my project, but I don’t think the asset affected this in some way, but I’m not so sure if it worked fine before.

From the error this looks like your DialogueScript is an autoload, if you put this as an autoload the code will fail because the path will be different from the path when the script is attached to the node you show in the photo. Check if you have any autoload with that script:

image

yes, my whole script is an autoload to be able to use the dialogue manager asset.

In this case you need to decide how this script will behave: Or you remove the script from autoload or remove from the dialogue box node and fixes the path to work from the root child.

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