Weird behaviour in a scene change manager

Godot Version

Godot v4.4.stable.official

Question

I’m losing my mind over this weird behavior so i’m here seeking for help now

For some reason when changing from my level scene to the death scene it doesn’t load anything after unloading the level scene, but this happens only when death scene’s script has a line of code for transitioning back in one of the functions that’s never even getting called.

My scene load function:
( loaded_scene is a Node2D that holds the loaded scene. )

func loadScene(scene:PackedScene):
	for child in loaded_scene.get_children():
		child.queue_free()
	var newscene = scene.instantiate()
	loaded_scene.add_child(newscene)

Transition function:

func change_scene(newScene:PackedScene,transition_in:int,transition_out:int):
	var anim_in = transitions_in.get(transition_in, "instant")
	var anim_out = transitions_out.get(transition_out, "instant_out")
	transition_player.play(anim_in)
	await transition_player.animation_finished
	loadScene(newScene)
	transition_player.play(anim_out)

Function in player’s script that switches to the death scene:

func death():
	music.mute = true
	g.camera.camera_moving = false
	if death_state == 0:
		velocity = Vector2(0,0)
		Sprite.play("Death Stun")
		fren_anim.play("death")
	if death_state == 1:
		Sprite.play("Hurt")
		fren_anim.play("hurt")
		velocity.y = -500
		velocity.x = -250 * last_dir
		def_col.disabled = true
		leg_col.disabled = true
		death_state = 2
		Sprite.z_index = 15
		g.game.changeScene(preload("res://Scenes/life_decrease.tscn"),3,3)

The life_decrease scene script has this function:

func change_back():
	g.game.changeScene(preload("res://Scenes/title_card.tscn"),3,0)

While this line of code is present i’m unable to load life_decrease scene from the level scene
But the function itself isn’t even called anywhere

And the issue persists only when trying to load it from the level scene, loading from other scenes works completely fine.
I have no idea what’s going on.

preload may be causing a cyclical dependency which resolves by failling to load. Keep in mind the “pre” part of preload means it’s happening before the script is loaded, the resources is tied directly to the code. If you use load instead then the script only has a String tied to it.