Scene Manager duplicates scene when changing level

Godot Version

4.2.2

Question

Hello, so I have a project of a Point and click game, I have a sprite that you can click to change levels, this one has a @export field in wich you can indicate the path of the next level, I also have a Fade autoload and a GameManager autoload, this one adds the scene that you indicated to the sprite to the tree and removes the current one when the Fade sends the signal.
The problem is that on each level I have a : “print(levelname)” on them and after switching multiple times back and forth between levels, these prints start to appear more and more in the output, even when you are not on that level, so you can switch back to level1 for the first time and it will print level1, level2 and level1.

This is the GameManager code:

This is the Game scene, where the levels get added:

Here you can download the project:

1 Like

I fixed it, I separated the lambda function into a different one (It seems like lambda functions give some problems) and limited the function to only be called once, I still don’t know why it was called multiple times.

func change_room(next_scene,fadetype):
	
	if changingroom==true: return
	changingroom=true
	
	managernextscene = next_scene
	SceneTransition.fade("roomchange",fadetype)
	manage_audio(next_scene)
	next_scene=null
	
func after_fade_in():

		
	rooms.get_child(0).queue_free()
		
	#for room in rooms.get_children():
		#room.queue_free()
		
	rooms.add_child(load(managernextscene).instantiate())
	managernextscene=null
	changingroom=false

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