change_scene() doesn't remove instanced sprites?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By GrafEisen


I’m using Godot v3.2 and there are a couple of sprites that I instance with the function, but when I change their z_index and then I call the change_scene() function they are not removed, the Sprites just stay there over the viewport for the next scene.

Is this expected behaviour? The sprites are removed when I don’t change their z_index.
Is there a better way to get rid of them instead of calling queue_free() before change_scene()?

edit: add script sample
Script running on HSplitContainer to create sprite when TextureButton is clicked:

func _on_TextureButton_pressed():
	var spr =
	image = spr
	spr.texture = load("res://Images/animation.png")
	spr.hframes = 2
	spr.frame = 0
	spr.z_index = 2
	spr.scale = Vector2(0.5,0.5)
    spr.position = get_tree().get_current_scene().get_node("spriteSpawn").position

Script running on scene root to start next scene:

func _on_BattleButton_pressed():

could you provide your script to debug

Thakee Nathees | 2020-04-11 07:42