How to change a sprite to another instanced sprite using gdscript

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

How can I get a node in a scene and chnage it to another node by instancing the node
i tried this but it didn’t really work.But it suprisingly printed the correct instanced sprite that I expected it to:

func _ready():
var sprite = get_child(3)

sprite = load("res://assets/super_platforms/slide_and_slope_straight.tscn").instance() #the same sprite remains

print( it prints out the root node of the instanced scene,which is part of what its supposed to do

:bust_in_silhouette: Reply From: Eric Ellingson

can you do something like this?

var sprite = get_child(3)
var new_sprite = load("res://assets/super_platforms/slide_and_slope_straight.tscn").instance()

# set any properties that need to be set
new_sprite.position = sprite.position

sprite.visible = false

Thanks worked well except that I had to change queue_free(sprite) to sprite.queue_free()

Titox | 2019-12-05 19:33

oh, duh, sorry about that. glad you got it worked out!

Eric Ellingson | 2019-12-05 21:09