Godot: Keeping project files organized and avoiding duplicates

https://lemmy.world/post/44856237

Godot: Keeping project files organized and avoiding duplicates - Lemmy.World

I’m working on a project that’s scaling up a bit fast in term of files and content. As such I need a way to keep these files organized. The godot documentation recommends keeping resources and assets close to their scenes. I used to do the opposite, separating assets by type and linking them in my scenes. Now, what the docs recommend is good but how to avoid duplications when you need to use the same resource at multiple places? Say you have a gunshot sound, your player can use it, your enemies too. ## Option A (the docs way): /enemies/cowboy/gunshot.ogg /enemies/cowboy/cowboy.tscn /enemies/turret/gunshot.ogg /enemies/turret/turret.tscn /player/gunshot.ogg /player/player.ogg Here I have a redundancy of gunshot.ogg, so if later I want to edit the sound, I have to remember to swap it at 3 different places. But on the other hand, the scenes are better “packed” for reusability on other projects and it “feels right” ## Option B (my way): /gameobjects/player.tscn /gameobjects/cowboy.tscn /gameobjects/turret.tscn /sounds/gunshot.ogg Here my naive way reduces redundancy, if I want to update the gunshot sound, I can just replace the one under /sounds/. The project is smaller which is also a (very) good benefit. However, if I want to make another game, reusing those scenes is a pain because I’m dealing with missing resources and finding who needs what to work. Is there a middle ground method, some Option C I’m not seeing? Thank you for reading ^^

Are other things shared? Especially in the code? They all have health, they all can shoot, they all can take damage. Make an object they all inherit from.

Or just make a shared assets folder

I would recommend composition over inheritance www.youtube.com/watch?v=74y6zWZfQKk

Then you’d have a component that enables shooting, and you can store related sound effects near that.

How You Can Easily Make Your Code Simpler in Godot 4

YouTube

In the problem of files organisation, this seems to only push it elsewhere.

Because now, if I make another game with my cowboy for example, I need to remember to take the shooting component with me. And all other components I would have made linked to this cowboy.

This would look like:

/components/shooting/shooting.tscn /components/shooting/gunshot.ogg /player/player.tscn /npc/cowboy/cowboy.tscn /npc/turret/turret.tscn

I guess this mitigates the issue at least 🤔

If you want to replicate stuff across multiple separate projects, I guess the best method would be to create your own plugins: docs.godotengine.org/en/…/making_plugins.html

For example you could assemble all of your custom components, including assets like sound effects, into a plugin that serves as a library of reusable components. Then you’d only need to add the plugin to whatever project you need them in and Godot would automatically take care of the file management.

Making plugins

About plugins: A plugin is a great way to extend the editor with useful tools. It can be made entirely with GDScript and standard scenes, without even reloading the editor. Unlike modules, you don&...

Godot Engine documentation