Cyclic level transition is not possible

Hello,

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:

E 0:00:00:0657   _parse_ext_resource: res://Scenes/level_3.tscn:17 - Parse Error: [ext_resource] referenced non-existent resource at: res://Scenes/level_2.tscn
  <C++ Source>   scene/resources/resource_format_text.cpp:162 @ _parse_ext_resource()

Do you know what could be causing it?

Thanks in advance!

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.

1 Like

yeah that was my sort of takeaway from it, that it was trying to preload and going through them.

nice one that you got a workaround. theres definitely a limitation there when using packed scenes
i did something similar

Problem with Level_3 “next level” - Other Courses / Ask - GameDev.tv

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms