How do I Instance a tree from the same scene?

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

I have an area 2d that adds a point to a scoreboard when it is touched, i have it so it randomly generates from another scene but the area 2d doesn’t add a point to the scoreboard. I think i need to instance the area 2d tree that is activating from the scene, how do I instance the tree inside the same scene?

:bust_in_silhouette: Reply From: IHate

If I understand correctly to do something as simple as adding points to a scoreboard you only need to connect the signal from the new area 2d to the function you are using on the current scene to add the points. But if you want to save the the area 2d on the other scene with all its children you can just save it as a scene (Right click: save branch as scene) then you load the scene on a variable and create an instance of the scene

I already did this, but the issue is it doesnt allow me to keep the area 2d connection from a different scene.

BreamkillerX | 2021-03-13 01:21

that’s why you have to connect the signal when you create the instance and add it to the new scene tree

export (PackedScene) var  Area2D_scn

var area= Area2D_scn.instance()
area.connect("input_event",(node with the points func),"(name of the func)")
add_child(area)

If the connections were made between the nodes of the scene you are instancing and they broke you can connect them again using the same method.

IHate | 2021-03-13 01:37