.. _doc_scenes_versus_scripts: When to use scenes versus scripts ================================= We've already covered how scenes and scripts are different. Scripts define an engine class extension with imperative code, scenes with declarative code. Each system's capabilities are different as a result. Scenes can define how an extended class initializes, but not what its behavior actually is. Scenes are often used in conjunction with a script so that the scene acts as an extension of the scripts declarative code. Anonymous types --------------- It *is* possible to completely define a scenes' contents using a script alone. This is, in essence, what the Godot Editor does, only in the C++ constructor of its objects. But, choosing which one to use can be a dilemma. Creating script instances is identical to creating in-engine classes whereas handling scenes requires a change in API: gdscript GDScript ``` const MyNode = preload("my_node.gd") const MyScene = preload("my_scene.tscn") var node = Node.new() var my_node = MyNode.new() # Same method call var my_scene = MyScene.instance() # Different method call var my_inherited_scene = MyScene.instance(PackedScene.GEN_EDIT_STATE_MAIN) # Create scene inheriting from MyScene ``` Also, scripts will operate a little slower than scenes due to the speed differences between engine and script code. The larger and more complex the node, the more reason there is to build it as a scene. Named types ----------- In some cases, a user can register a script as a new type within the editor itself. This displays it as a new type in the node or resource creation dialog with an optional icon. In these cases, the user's ability to use the script is much more streamlined. Rather than having to... 1. Know the base type of the script they would like to use. 2. Create an instance of that base type. 3. Add the script to the node. 1. (Drag-n-drop method) 1. Find the script in the FileSystem dock. 2. Drag and drop the script onto the node in the Scene dock. 2. (Property method) 1. Scroll down to the bottom of the Inspector to find the `script` property and select it. 2. Select "Load" from the dropdown. 3. Select the script from the file dialog. With a registered script, the scripted type instead becomes a creation option like the other nodes and resources in the system. One need not do any of the above work. The creation dialog even has a search bar to look up the type by name. There are two systems for registering types... - `Custom Types