Need help adding thousands of item to the build menu through code

Godot Version

4.0

Question

`Hello everyone, I am currently searching for a way to put spawn thousands of object in the build menu before debugging, but I cant just put them in by hand, and as such I want to know if there is a way in godot to spawn in many objects just like in debugging with “addchild()” or “addsibling()” but instead it is put in this menu permanently

.
Thank you and I hope you have a great day.

You can write a code that does this, then save your scene with this code at the end, then use the output file instead of the current scene:


var scene = PackedScene.new()

scene.pack($".")

ResourceSaver.save(scene, "res://NewScene.tscn")

Also you can use get_node(“path/to/node”) instead $“.” for save a node with its children

I am really sorry to ask this of you, but I genuinely have no idea what that means, are you able to sent screenshots of the process or is it too long?

This is the process:
Add this code to the script of the highest node in the scene:

func _ready():
  var scene = PackedScene.new()
  var parent = $"."
  var instance = $"path/to/node"
  for i in range(100): #number of instances
    parent.add_child(instance.instance())
  scene.pack(parent)
  ResourceSaver.save(scene, "res://NewScene.tscn")

Run the scene, a NewScene file will be created in the project directory that has 100 new instances.

Thank you so much man, im sorry ive been away for so long, had personal problems piling up. I hope you had a great week and that it continues.

1 Like