Best practises for reusable, customizable component design

Hi there!

I’m pretty far into a project with Godot. As my library of assets grows in the last stretch of adding content, I’m stumbling upon an issue:
Many assets have shared parts of customizable behaviour, and I’m struggling to find a clean solution to reuse them. For a simple example, there are a lot of buttons, levers, lifts, platforms… etc, that can be color-coded in the editor.

In order to not duplicate code across many different scripts, I introduced a “Colorizer” script which has a Color property. I attach this to a child node of the asset that should be color-codeable, and it takes care of everything.
However, as this new node is nested in the asset scenes, I can’t customize the color when I create an instance of the asset scene in a level - at least, not without checking “editable children”, which would become super awkward to manage in large scenes.
What I’m currently doing is to duplicate the “Color” property into the root script of each asset, so I can customize it on the root node. I’m also duplicating code that’s handing the property values to the Colorizer node. That’s is clearly suboptimal.

Mind you, I’m not looking for advice on how to solve the issue for the Color property in particular - it’s the simplest example of many, just for illustration purposes.

Rather, the question is: How do you design your components in general, so that they are both resuable and configurable when they’re part of an asset scene? Do you have any best practises, experiences or design patterns that would help to achieve this?

First: I don’t have an answer. I’m commenting because this incentivized me to do some thinking / research.

This seems to be one of the Achilles heels of Godot’s node based system.

The most commonly suggested method is indeed using Editable Children. The next best thing is your current approach of relaying properties from the root to its children. Both are sub optimal (old Github issue that mentions this problem).

This goes so far as to a proposal for this to be implemented as a GDScript feature: Add a Trait system for GDScript · Issue #6416 · godotengine/godot-proposals · GitHub

Really curious if someone else has a better answer for this.

1 Like

Object oriented programming.