The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

How do a create a completly new scene from gdscript, there seems to be no Scene class.

Godot version 3.2.3
in Engine by (2,018 points)

2 Answers

+1 vote
Best answer

A scene is just a node and it's children saved to a file. That's all.

You probably just want to create a node and then add some children to it. If you relly want to save a scene (I.e. because you're working on an editor plugin) than this QA-post might help you.

by (330 points)
selected by

Thanks, this definitely helps.

0 votes

See Nodes and scene instances for godot 4 or godot 3.6.

Here's some examples copied from that page.

Building a new scene

var sprite2d

func _ready():
    var sprite2d = Sprite2D.new() # Create a new Sprite2D.
    add_child(sprite2d) # Add it as a child of this node.

func _done():
    sprite2d.queue_free()

Instantiating a new scene from the project

If you already built and saved a scene but it's not already in the active scene, you can instantiate it.

var scene = preload("res://my_scene.tscn")
func _on_Area_body_entered():
    var instance = scene.instantiate()
    add_child(instance)
by (154 points)

(This question has high pagerank, so I wanted to add answers that would have helped me when I started looking.)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.