I was encountering some weird problems while loading from a scene to another and then back, so to check my sanity I made a minimal reproducible example of the problem.
My minimal example is the following.
Two scenes, that are visually distinguishable, they both have at their root a copy of this script, with "next_scene" set to the other scene.
extends Node2D
@export var next_scene: PackedScene = null
func _process(delta: float) -> void:
if Input.is_action_just_pressed("space"):
print(next_scene)
get_tree().change_scene_to_packed(next_scene)
Expected behavior:
I would be able to navigate from one to another back and forth.
Actual behavior:
First load goes well, then going back fails because "next_scene" is said to be null
This happens no matter which scene I start with, proving that it isn't my setup that is wrong.
I tried to implement my own scene manager that would instantiate and queue_free() nodes instead, but I get IDENTICAL behavior.
At this point I'm losing my mind as I've been at it for a few hours
.