how to add more than one node at the same time

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

hello there i would like to add more than one node at the same time instead of going back to create one each time

Do you mean in the editor or using var new_node = Node.new() code repetitively?

Magso | 2020-03-25 03:14

in editor press ctrl + d to duplicate node

supper_raptor | 2020-03-25 04:35

i don’t want to duplicate i want to be able to add for example collision2D with sprite

payload505 | 2020-03-25 07:58

yes you can add collision2d with sprite , just add sprite child of collision 2d

supper_raptor | 2020-03-25 08:46

:bust_in_silhouette: Reply From: the.Alien

I think that you’re asking how to do it from the editor.
You should usually add one node at time; however, I think that your problem is that you’re creating many different “blocks” and you don’t want to iterate the process each time. In that case you should create a single node with all its sub-nodes; when you’re happy with it, create a scene from it. From now on you simply load the scene each time you want to add a whole “block” (either in the editor or from code).

helpful thanks

payload505 | 2020-03-25 18:49

Iam actually a begginer iam not creating alot of things i just think it’s annoying

payload505 | 2020-03-25 18:51

:bust_in_silhouette: Reply From: Magso

It’s also possible to make a tool script to quickly create commonly used nodes for example, attach this script to the scene node and clicking the bools in the inspector will create the nodes.

tool
extends Node

var mesh_instance : bool
var static_body : bool

func _process(delta):
    if mesh_instance:
        mesh_instance = false
        var new_mesh = MeshInstance.new()
        add_child(new_mesh)
    
    if static_body:
        static_body = false
        var new_body = StaticBody.new()
        var collider = CollisionShape.new()
        add_child(new_body)
        new_body.add_child(collider)