Olli
Olli

Reputation: 1

Godot: Error when navigating between pages "referenced non existent resource"

I have a problem in my code.

enter image description here

All the buttons are clickable. But when entering the leaderboard.

And pressing the exit button.

All the buttons become unusable and do nothing. Here are the errors.

_parse_ext_resource: res://scenes/main_menu.tscn:16 - Parse Error: [ext_resource] referenced non existent resource at res://script/main_menu.gd

set_path: Another resource is loaded from path 'res://scenes/main_menu.tscn' (possible cyclic resource inclusion)

Screenshot of the above error messages

Here is the code of the main menu:

class_name MainMenu
    
extends Control
    
@onready var play_button = $MarginContainer/HBoxContainer/VBoxContainer/Play_Buttom as Button
@onready var exit_button = $MarginContainer/HBoxContainer/VBoxContainer/Exit_Button as Button
@onready var leaderboar_button = $MarginContainer/HBoxContainer/VBoxContainer/Leaderboar_Button as Button
@onready var start_level = preload("res://scenes/game.tscn")
@onready var start_mainmenu = preload("res://scenes/leader_board.tscn")
    
func _ready():
    play_button.button_down.connect(on_play_pressed)
    exit_button.button_down.connect(on_exit_pressed)
    leaderboar_button.button_down.connect(on_leaderboard_pressed)

func on_play_pressed() -> void:
    get_tree().change_scene_to_packed(start_level)

func on_exit_pressed() -> void:
    get_tree().quit()

func on_leaderboard_pressed() -> void:
    get_tree().change_scene_to_packed(start_mainmenu)

And here is the code of the leaderboard:

extends Control
    
@onready var exit_button = $MarginContainer/HBoxContainer/VBoxContainer/Exit_Button
@onready var main_menu = preload("res://scenes/main_menu.tscn")
    
# Called when the node enters the scene tree for the first time.
func _ready(
    exit_button.button_down.connect(open_main_menu)

func open_main_menu():
    get_tree().change_scene_to_packed(main_menu)

I have tried everything, but Ihave no clue how to fix this.

Upvotes: 0

Views: 161

Answers (1)

superlamapl
superlamapl

Reputation: 1

Got same problem today - open main_menu.tscn in text editor and remove lines where references to variables listed in @onload are set. Then reopen project and set variables again.

I think it broke when I duplicated level files and forgot to change references to next levels. Also I had the same level's root node names.

Upvotes: 0

Related Questions