Why won't my screen manager let me load a second game?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By YangTegap

I have a screen manager in my project that I use to go from the home screen to the game screen, then back to the home screen. THAT works all fine and dandy, but then after being at the home screen for the SECOND time it won’t let me load a new game, and I can’t figure out why.

Here is the screen manager:

extends Node2D

onready var current_screen = $HomeScreen

func to_screen(new_screen):
	new_screen = load(new_screen).instance()
	add_child(new_screen)
	current_screen.queue_free()
	current_screen = new_screen

func to_home_screen():
	to_screen("res://assets/screens/HomeScreen.tscn")

Then here is what happens when I call a new game from the home screen:

func new_game():
	load_save_path()
	screen_manager.to_screen("res://assets/screens/GameScreen.tscn")

When I try to load a second game, I get an error that says, “ERROR: Attempted method call on a deleted object.”

What am I missing?

Singletons (AutoLoad) — Godot Engine (3.1) documentation in English

func to_screen(new_screen):
   new_screen = load(new_screen).instance()
   add_child(new_screen)
   current_screen.queue_free() // maybe this. .queue_free()
   current_screen = new_screen

ramazan | 2022-03-03 10:00