![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Rickers |
I am currently experimenting with the removal and reloading scenes and am using the following code, which is run in the Main Scene:
extends Node2D
var dialogue_getters = preload("res://src/dialogue_get_funcs.tscn").instance()
var dialogue_box = preload("res://src/dialogue_box_creator.tscn").instance()
func _input(event):
if Input.is_key_pressed(KEY_UP):
add_child(dialogue_getters)
add_child(dialogue_box)
var old_man_shouting = $Node2D/dialogue_line_get.get_line("old_man","shouting")
$Dialogue_box_root/dialogue_box.dialogue = old_man_shouting
elif Input.is_key_pressed(KEY_DOWN):
dialogue_getters.queue_free()
dialogue_box.queue_free()
When I run this, I press UP and I get the box appearing and the inserted dialogue showing up just fine. Similarly when I press DOWN the box disappears.
However, if I try to press UP again I get the following error message:
Invalid type in function 'add_child' in base 'Node2D (dialogue_main.gd)'. The Object-derived class of argument 1 (previously freed instance) is not a subclass of the expected argument class.
Which is confusing me as I don’t really understand what the error message is telling me.
I have tried noodilng around with the code, such as adding or replacing queue_free with “remove child” but if I understand correctly “remove_child” doesn’t actually free the scene from the memory (and if I just use remove_child and then re-add the child I just get a continuation of the current dialogue, rather than a restart).
I’ve tried to look everywhere but no one else seems to have this issue (It would be great if someone could point me to where I can read about reloading scenes in the documentation as well so I can better understand this part of the engine.)