How to add objects to scene from script?

Godot Version

4.5.1

Question

How do I add objects to a scene from a script? I am making a 2D sidescroller platformer game that adds random stages so the game scrolls infinitely, but I don't know how to add a new stage section to an existing scene. All responses appreciated. Sorry if this post is basic, I am very new to Godot.

Hey, welcome to the forums! I recommend reading up on how ResourceLoader works, which can be used to load a PackedScene, then you can use the add_child function to add the loaded scene(s) to any node you wish.

I also recommend doing the first basic games, such as this one:

4 Likes