I have 2 different visual styles in the game I'm working on, and the terrain is loaded / updated dynamically. These styles are often switched by changing a shader parameter. This shader parameter should always be up-to-date with the global style, so parts of the terrain need to react to changes, but also set the current style when first instanced.
In each Node with such a shader, set the flag accordingly at the beginning and react to each style change. This results in a lot of duplicate code and is easy to forget when adding or adapting a Node with that shader.
Inherit from a script which handles style switching in the shader. As far as I can tell, this is not an option because this will be done by different types of Nodes (Meshes, Particles, ...)
Add Nodes which switch style by changing a shader parameter to a group and update all Nodes in that group when the style changes. This works well and I find it quite clean, since individual Nodes with that shader don't have know about styles at all. However, this only works when the style changes - if the style has changed and a Node is instanced after the style change, it doesn't have the according style.
In Solution 1 and 2, I could resolve this by setting the initial style in the _ready function. However, I can't find a way to do that with groups except for constantly iterating over all of them, which would be hugely inefficient.
Essentially, it'd be ideal if I could add code which is called for all Nodes in a group when they're instanced.
Can anyone think of a way to do this (or a completely different, even better solution)?