Skip to content

Godot: code architecture

How to structure scenes, nodes and scripts so that the game stays easy to change: scene design and communication, scripting languages and style, input and UI layout, multiplayer, and threads. Engine-independent patterns, such as components, fixed time steps and authoritative servers, are in Game development.

Entries are sorted by score from 1 to 10 (criteria): 9โ€“10 start here or strongly recommended, 6โ€“8 recommended, 1โ€“5 further reading or conditional.

Adopted references

  • 8 GDScript style guide (Godot docs): formatting, naming conventions and code order.
  • 7 Static typing in GDScript (Godot docs): typed variables and functions, and the warnings that help you keep code typed.
  • 7 High-level multiplayer (Godot docs): peers and connections, RPCs with their transfer modes and channels, authentication, and secure multiplayer design.
  • 7 Optimization using Servers (Godot docs): bypassing the scene tree and driving the rendering, physics and audio servers directly through RIDs, for tens of thousands of objects once other optimisations are exhausted.

Key rules

Scenes and nodes

  • 8 GODOT-3 Design scenes to work on their own: keep what a scene needs inside it, and let the parent supply any outside dependency. The parent can connect to the scene's signals or set its properties, Callables and node references. (Godot, Scene organization)
  • 7 GODOT-4 Let parents call methods on and set properties of their children, and let children report what happened through signals. Siblings communicate through a common ancestor. Name signals with past-tense verbs, such as item_collected. (Godot, Scene organization, Using signals)
  • 7 GODOT-5 Use autoloads only for broad-scoped systems that manage their own data, such as a quest or dialogue system. Share helper functions with static func in a class_name script, and share data with a custom Resource. (Godot, Autoloads versus regular nodes)
  • 6 GODOT-6 Reference other nodes through @export properties or scene-unique names (%Name), not long hard-coded node paths. These references keep working when nodes move in the scene tree. (Godot interfaces, Scene unique nodes)
  • 5 GODOT-7 Make game-specific concepts scenes, and use named script classes for reusable tools shared across projects. (Godot, When to use scenes versus scripts)
  • 5 GODOT-8 Use RefCounted or Resource classes instead of nodes for data and logic that don't need to be in the scene tree. (Godot, When and how to avoid using nodes for everything)

Scripts

  • 7 GODOT-21 Choose the scripting languages early: GDScript suits most game code, C# suits teams that already know it, as long as you don't ship to the web, and C++ through GDExtension suits performance-critical algorithms. You can mix them in one project. Godot 4 can't export C# projects to the web, its C# support on Android and iOS is experimental, and C# code can pause for garbage collection. (Godot, Scripting languages, C# basics, CPU optimization: languages, About godot-cpp)
  • 7 GODOT-9 Use static typing throughout, and set the untyped_declaration warning to Error so that untyped declarations stop a script from compiling. Typed code catches more errors before it runs, and it runs faster. (Godot, Static typing in GDScript, GDScript warning system)
  • 7 GODOT-11 Move objects and run game logic in _physics_process, and turn on physics interpolation so that motion stays smooth at any frame rate. Use _process only for work that must follow the rendered frame rate. (Godot, Using physics interpolation, Godot notifications, game development: fixed time steps)
  • 6 GODOT-10 Follow the GDScript style guide, including its code order. Consistency within the team matters more than any single convention. (Godot, GDScript style guide)

Input and UI

  • 7 GODOT-22 Read player input through actions defined in the Input Map, not specific keys or buttons, and handle gameplay input events in _unhandled_input() rather than _input(), so that UI controls receive them first. One action can map to several keys and gamepad buttons, and you can build runtime rebinding on top of the Input Map (GAMEDEV-18). (Godot, Using InputEvent, InputMap)
  • 6 GODOT-23 Set the base window size, stretch mode and stretch aspect at the start, following the docs' recommended settings for your kind of game, and lay out UI with anchors and Container nodes so that it adapts to every resolution and aspect ratio. Games that aren't pixel art usually take the canvas_items stretch mode and the expand aspect, the default for projects created in Godot 4.7 and later; pixel-art games take viewport with integer scaling. (Godot, Multiple resolutions: common use case scenarios, Using Containers)

Accessibility

Multiplayer and threads

  • 7 GODOT-24 In multiplayer games, replicate spawned scenes with MultiplayerSpawner and properties with MultiplayerSynchronizer, keep the server the multiplayer authority over gameplay state, and give each player authority only over a child node that sends their input. Validate the arguments of every RPC that clients may call (any_peer) before applying them, using multiplayer.get_remote_sender_id() to know who sent it. This applies GAMEDEV-5. (Godot, High-level multiplayer: secure multiplayer design, MultiplayerSpawner, MultiplayerSynchronizer, Multiplayer in Godot 4.0: Scene Replication)
  • 6 GODOT-25 Don't change the active scene tree from another thread: build or load nodes outside the tree in the worker thread and add them on the main thread with call_deferred(), don't load the same resource from several threads at once, and protect data that threads share with a Mutex. Check which engine classes a thread may use first; the rendering and physics servers are thread-safe only after you turn on their threading project settings. (Godot, Thread-safe APIs, Using multiple threads)

How to enforce

Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.

  • 7 GDScript warning system: set untyped_declaration to Error in Project Settings, and scripts with untyped variables, parameters or return types no longer compile. Checks GODOT-9.
  • 5 gdlint and gdformat (gdtoolkit): gdlint checks names against the style guide's conventions and the order of class definitions, and gdformat --check fails when a file would be reformatted. Both exit with a non-zero code, so they work in CI or a pre-commit hook. Partly checks GODOT-10.

Tutorials and further reading