How would you setup and structure a project (with a focus on scripting)?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By indicainkwell
:warning: Old Version Published before Godot 3 was released.

In Unity you would create scripts that could be small and specific and then attach any number of them to a game object to build functionality. For a very simple example: you have 3 scripts that rotate the game object on one of the x, y, or z axes. In the scene you have 4 game objects; 1 rotate on all axes, 1 to rotate on xy axis, 1 to rotate on x axis, and 1 to rotate on yz axis.

You add the scripts with the intended functionality as components to the game object.

In godot it appears you have to write a new script for each functionality or add some more code to an existing script on a node. Which seems like it can really bloat a script on a specific node.

I was thinking of creating an empty Node and adding sub nodes with scripts. Kind of acting like a folder. Then instance that Node under some other node that I want to get the functionality of that “folder” of scripts by exporting a NodePath var in the parent Node and pass it to the functional sub nodes.

I haven’t done that because it seems like an anti pattern and you can’t directly handle stuff like input and drawing you’d have to create a mediator object of some sort.

Also, how’s subclassing from another gdscript? I’ve read somewhere from experienced godot users that they don’t use the extends "some-script.gd" Why is that? Other than you don’t get autocompletions in the script editor.

:bust_in_silhouette: Reply From: Zylann

In Unity, a GameObject does nothing until you add components to them.
In Godot, a node can only do one thing at a time, so usually we build actors as a node with children, as you said, like a folder. It works pretty well for me so far. Hierarchy and names are more important in Godot than Unity.

The way I usually go for each scene is to have the most high level stuff in the root node, and specific tasks are then delegated to children with get_node().do_stuff() or signals, making children script more re-usable.

I used extends "some_script.gd" a few times in my project, but this is mostly to reuse code and make it more specific.

My feeling with Godot so far is “keep it simple”. So I don’t worry too much on code structure, the scene system does that brilliantly already. This is what scripting is meant to be, to get things done first rather than thinking about structure. Maybe I will refactor my code when my project gets too complex, but it hasn’t happened yet :stuck_out_tongue:

This helped, thank you for posting!

I continued on with the project with the mindset of KISS (keep it simple, stupid) and to have the root node as a delegator and that helped a lot.

indicainkwell | 2016-06-02 06:01