Having multiple Nodes2D in a scene or having none - Godot

1.1k views Asked by At

I am studying Godot engine and I was wondering why I can't have multiple nodes or element by themselves in the scene. Godot doesn't allow me that. Why?

1

There are 1 answers

0
Cody Parker On BEST ANSWER

A scene can only have one root node by design. This allows a scene to be a contained node tree. There isn't a need for multiple root nodes because these scenes can be added together to form more complex scenes.

For example, you could have a Car scene that is comprised of several nodes that define your car (sprite, physics nodes, etc). You could then have a Street scene that has nodes that define how your street looks and works.

Now you add a car on to the street by creating an instance of the car scene in your street scene (either by script or in the editor). You could even add more car scene instances for more cars on the street. And if you wanted this street scene, with all of its cars added to a Town scene, you would just instance this street scene there. And again, you could do that for multiple streets to have tons of streets with cars.

So, you would always have a root node (in the final case here - the root node of Town) that would contain a tree of nodes that you've instanced into it.

I hope I explained it well enough.

Take a look at the docs for information on this: http://docs.godotengine.org/en/stable/learning/step_by_step/instancing.html