Help with getting a node

Godot Version

4.2.1 Stable

Question

My code when I call the display_message() method i crashes with the error:

E 0:00:01:0212 MessageManager.gd:5 @ _ready(): Node not found: “CanvasLayer/MarginContainer/Panel/MessageText” (relative to “/root/TutorialLevel2/MessageManager”).

heres the code for the MessageManager:

extends Node

signal message_displayed

@onready var message_text = $CanvasLayer/MarginContainer/Panel/MessageText
@onready var message_audio = $MessageAudio
@onready var message_ui = $MessageUI

func _ready():
	message_ui.hide()

func display_message(message: String) -> void:
	message_text.text = message
	message_ui.show()
	message_audio.play()
	await get_tree().create_timer(0.5).timeout
	message_ui.hide()
	message_text.text = "message"
    message_displayed.emit()

Can you show your scene tree?

image_2024-05-04_223906935
here it is

Ah! I bet the issue is that you’ve renamed your CanvasLayer to MessageUI, so it should be:

@onready var message_text = $MessageUI/MarginContainer/Panel/MessageText

oh my god…
anyway thanks for pointing out my stupidity

Hey, sometimes you need a second pair of eyes!

yep sometimes

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