A Basic Godot-Rust Structure

Tom Leys
Tom Leys
Sep 21, 2019 · 2 min read

After posting Gorgeous Godot games in Rust I have had some questions about how to structure a Godot and Rust project. I’m only just starting on my own, but I thought I would share.

My project (which is in /game/ in my repo) looks like this

The scripts you see below are primarily using the node root/Root/Ships above. They create subscenes under that for each ship. Then inside each ship a floor and various modules are created.

My source project structure currently looks like this.

Godot-rust and Cobalt (UDP networking) are in the rs/lib folder. Each of these is a “Git Submodule” in my repository. That means I can lock it to a specific commit (for each of my commits) and can make mods and push them back upstream very easily.

My code is in the rs/sg folder (Space Game)

The game folder contains the Godot project.

My projects are:

  • sg_simulation (which is pure simulation, tested with unit tests. It has few dependencies)
  • sg_net (Uses sg_simulation, pulls in UDP networking and exposes server/client functionality)
  • sg_server (Standalone server, can also be run as a client. Pulls in sg_simulation and sg_net)
  • sg_core (This library is used by Godot, it pulls in sg_simulation, sg_net)

Inside sg_core, the cargo.toml file looks like this

Then the sg_core contains lib.rs. I decided to put all the classes exposed to godot into a module called “bridge” I could even move the function “init” if I wanted to. To understand how this file has been split out, you need to understand how rust modules work.

Floor tiles for instance looks like this

I hope this gives you some ideas on how you can structure and break up your own work.

Tom Leys

Written by

Tom Leys

Making a space game

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade