Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Jeremias |
How can I make it so I can reset a specific child without having to restart the whole scene
I tried this
var playerScreen=preload("res://playerScreen.tscn")
var t = playerScreen.instance()
func _input(ev):
if Input.is_key_pressed(KEY_R):
remove_child(t)
add_child(t)
But it just ends up canceling out, I would really appreciate if somebody could help me out
It isn’t really cancelling out though is it?
You remove ‘t’ from the scene tree but ‘t’ still exists exactly as it was when removed.
So then you immediately add it back to the scene tree and you see the same ‘t’ that you just removed.
There is another way to reset your scene (other than the one jgodfrey suggested below).
You can add a reset()
function inside your child scene node. This function can then zero out that what needs zeroing and reset that what needs reseting.
func _input(ev):
if Input.is_key_pressed(KEY_R):
t.reset()
LeslieS | 2023-01-06 01:59