Issue with gameobject becoming invalid when loading scenes using add_child

I’m encountering an issue when using add_child to load a scene.

func _switch_to(room_scene: PackedScene) -> void:
	if current_scene:
		current_scene.queue_free()

	current_scene = room_scene.instantiate()
	scene_layer.add_child(current_scene)

As shown in the code, I’m trying to load the scene by replacing the child node. This is because my project uses a SubViewport node to display a 2D camera window, allowing the game view and UI to coexist.


However, I’m running into a problem. If I instantiate the scene directly:



The GameObject can be interacted with normally.

But if I add the scene via code:



The GameObject cannot be interacted with properly.

The collision settings haven’t changed during this process; the only difference is the loading method. Could someone advise on how to resolve this issue?

If I understand correctly, when you add the GameObject via code, the GameObject doesn’t interact correctly?

I do know when you add GameObjects via code you need to register them to the AGMakerManager like this:
AGMakerManager.regist_game_object(“TargetNode”)

Can you try that and see if it works?

Thank you! In fact, to move the project forward, I’ve since replaced the relevant GameObject with a Node2D node. I’ll try the solution you provided later on a minimal reproduction project for this issue.