0 votes

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?

Godot version 3.4.2
in Engine by (93 points)

https://docs.godotengine.org/en/3.1/getting_started/step_by_step/singletons_autoload.html#custom-scene-switcher

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

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.