General Godot project structure
One of my first issues when starting a project is how to structure everything. So I had to spend some time researching best practices and go with what I like the most.
The first place to look for is of course the official Godot documentation on Project organization; along with project structure discussion, also comes with best practices for code style and what-not. I don’t like this project/directory structure that much, just because it tells you to bundle everything under the same directory but it’s a really good starting point, for example it tells you to use:
- /models/town/house/
- house.dae
- window.png
- door.png
Where I would prefer to have more modularity, for example:
- /levels/structures/town/house (or /levels/town/structures/house)
- window/
- window.x
- window.y
- window.z
- door/
- …
- house.x
- house.y
- house.z
- window/
It might look like it’s more work, but I prefer it like this. I wish this site was still available, as I got most of my ideas from there, but apparently the owner is not maintaining his site anymore; but there is this excelent comment on reddit which shows a project/sirectory structure more in line with what I’m currently using (and similr to the site that is down that I liked that much). I just do somethings a bit different, and end up with:
- /.git
- /assets (raw assets/editable assets for their respective software, could also be the whole imported assets from some packs, where you can just select few of them to actually use)
- /releases (executables ready to publish)
- /src (the actual godot project)
- .godot/
- actors/ (or entities)
- player/
- assets/
- sprites/
- …
- enemy/ (this could be a dir with subdirectories for each type of enemy for example…)
- assets/
- sprites/
- …
- actor.gd
- …
- player/
- levels/ (or scenes)
- common/
- assets/
- sprites/
- …
- main/
- …
- overworld/
- …
- dugeon/
- …
- Game.tscn (I consider the “game” itself a level/scene, so I’m including it here)
- game.gd
- common/
- objects/
- box/
- …
- …
- box/
- screens/
- main_menu/
- …
- …
- main_menu/
- globals/ (singletons/autoloads)
- ui/
- menus/
- …
- …
- menus/
- Main.tscn (the entry point of the game)
- main.gd
- icon.png
- project.godot
- …
- \<any other repository related files>
And so on, I hope the idea is clear. Basically you need to abstract some entity/object that you’re going to use into its more basic form and use subdirectories for each level of abstraction (a player is an actor and thus we use actor/player; a box is part of the world, and is a level so we can use levels/common/decor/box or something like that). Once you have the most basic abstraction done, anything that belongs to that abstraction will have all of its assets/sounds/shaders/etc in it’s directory.
By David Luévano
Created: Sun, May 22, 2022 @ 01:16 UTC
Modified: Sun, May 22, 2022 @ 01:23 UTC