Hi,

I commonly create a scene and attach a script to it. Even for simple "Node" types, without any child nodes. But you can also instantiate scripts directly in the editor without a special scene for it. Then, godot will create a new node and attach the script.

But there is a difference if you open the scene in with a text editor.

The first time, a packed scene resource is referenced. The second time, the script is referenced directly.

The question is, what are the up or downsides of both methods? Especially for scenes without any child nodes. I would guess the performance is better without a packed scene.

    abgenullt Once the thing is instantiated there's no difference in performance. Scenes do not exist as entities in the scene tree at runtime. In both cases you'll end up with a single node attached to the tree.

    abgenullt But you can also instantiate scripts directly in the editor without a special scene for it. Then, godot will create a new node and attach the script.

    How do you do that?

    • xyz replied to this.

      DaveTheCoder How do you do that?

      Click plus icon (Add Child Node) in the scene tree and select the script class. The class must be named though.

        DaveTheCoder Do you mean the node type?

        Named script classes will appear as custom node types alongside built in node types.

        Correct. You have to specify a "class_name". I use this to reduce complexity and the amounts of files. But as the question says, there could be some disadvantages.

        • xyz replied to this.

          abgenullt there could be some disadvantages

          Not really. The packed scene requires some additional storage but in case of just one node - that's negligible.

          However should you later decide that your component needs additional node or two and you already have many of it instantiated, then using a scene is clearly advantageous as you can easily extend it. All instances will "automatically" update. With a plain node, you can't do this. At least not in a simple way.

          So as a rule of thumb, if your node acts as a reusable component, it's always better to wrap it into a scene. After all, Godot is built to work with scenes.

            xyz That is a good point. Especially if you want to add childs later.