Godot Version
4.3
Question
So I’ve been trying to implement a way of managing the colours of things in my project. Godot does have the in-built theme system, but that only works for UI elements. I would like an easy way of standardising colours, and one place to change a certain colour that updates it everywhere else that it is used.
I’ve gotten most of the way to this goal but have run into one issue.
I have a resource class called Colours - this holds an array of ColourData resources. ColourData simply holds a name, a colour, and an ID.
My EditorPlugin overrides the property of ColourData in the inspector, instead showing a dropdown consisting of the elements in the Colours resource array.
That looks like this:
So that dropdown is an exported variable of type ColourData, but the plugin changes it to pull it’s values from this resource:
My issues is in updating the nodes that use a colour when it changes in the resource. So using the above image as an example, if I were to change the colour of “BlueHighlight” I would want everywhere in the opened scene to have that change reflected immediately.
The closest I have gotten to doing this, is when the node that the EditorProperty is attached to is selected, if it doesn’t already exist it adds itself to an array in an autoload - and whenever the Colours resource changes it sends a signal to the autoload script telling it to loop over all of the nodes and just set the colour to itself, updating them. This also works when they are no longer selected, because they have already been added to the array.
But in order for this to work, wherever there is a node with a ColourData property, it has to be selected at least once since the project was opened for it to update, because otherwise it isn’t added to the array. The EditorProperty script only exists while the node with that property is selected, the moment that it is no longer selected - no code will run.
Here’s a video hopefully showing what I mean:
I’ve spent days trying to find a solution to this issue and have come up empty handed - any advice would be greatly appreciated. Although I’ve sunk a lot of time into this, entire alternate ways of achieving this are also welcomed. I don’t really care how it’s done - I just want it to work
Thanks for taking the time to read.