I managed to solve it using an Autoload level manager instance, below is the code that fixed the circular dependency.
extends Node
class_name LevelManager
const levels = [
"res://Scenes/level.tscn",
"res://Scenes/level_2.tscn",
"res://Scenes/level_3.tscn"
]
func load_level(index: int):
if len(levels) <= index:
return
get_tree().change_scene_to_file(levels[index])
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
Level 1: next_level_index = 1
Level 2: next_level_index = 2
Level 3: next_level_index = 1
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.