Hi! I'm trying to build a level manager for my game to shift around scenes. I tried to follow this guide exactly, but I must be doing something wrong because it's not quite working. Here's the relevant portions of my code:
func _on_level_1_change_level(target):
match target:
"level_2":
new_scene = preload("res://Levels/level_2.tscn").instantiate()
position = Vector2($Hero.position.x, 1036)
change_to()func change_to():
get_tree().root.call_deferred("add_child", new_scene)
get_node("Level1").call_deferred("free")
$Hero.position = position
It does swap out the level and reposition the hero as intended, but while it loads Level2, it doesn't add it as a child of my level manager, so I can't connect to it and start monitoring for level swaps again. If I try to set up a connect function for it, it gives me a null-instance error, and when I ask it to print all the node's children to double-check, Level2 isn't on there. I feel like I'm doing all the things the guide said to (Technically I'm using a call_deferred when it didn't, but I also tried without that and get the same result) so I'm not sure what's going wrong?
EDIT: As a note, I also checked if it was a child of the main Game Manager node that parents my Level Manager, and it wasn't on that either. I have no idea where it's going, but the level itself does load.