Using the load method explained in this lecture the game isn’t able to load an already loaded scene.
For more context, I tried making a cyclic level reference, as follows: Level 1 → Level 2 → Level 3 → Level 1, making the game infinite, but when in the 3rd level I would get the following error:
As a side note, when I closed and re opened the project with the circular dependency references, it wasn’t able to load the scenes and was throwing exceptions when trying to open them, in order to fix that I had to open the serialized file and delete one of the references that was causing the cycle.
The new loading logic allowed for this setup for each level:
#...
@export var next_level_index: int
#...
func _on_exit_player_entered(player):
exit.animate()
player.disable_movement()
await get_tree().create_timer(1).timeout
LevelManagerInstance.load_level(next_level_index) # The autoload instance of LevelManager
This causes the game to loop from the 2nd level forward, so if you finish the 3rd level you go back to the 2nd one, indefinitely.
If there is any other easier workaround, or cleaner one, please let me know. In the meantime, at least now we have a solution for these kinds of references.