TLD,DR: for accessing exported properties in children nodes, one can toggle editable children
. But toggling editable children
creates problems: it puts the children out of sync with the original scene changes. If the original scene changes, there's no way to sync them automatically back.
Problem
Three classes A, B, and C, that each extend a different base class and have no inheritance overlap (they can't be traced to a single ancestor).
They all implement the same behaviors X. X is added as a child of each of those classes.
X has export
ed properties that need to be accessible in the editor. The solution to that is to set editable children
to true
in each of the instances of A, B, and C.
The problem is, when any of those classes change, editable children
do not sync with the changes. It seems all properties of children are copied in the root scene, and then take over any new defaults that would be set in the original scene. Every time A, B, C, or X changes, every scene where they're used (and where their editable children
bit is true
) throws a bunch of errors.
The only workaround seems to:
1. Check the editable X and note what properties are changed
2. set editable children
to false
, which resets all locally changed vars
3. set editable children
back to true
4. manually edit the properties of X again
This is, of course, very cumbersome and error prone. Specially that the real life example has many more classes than 3, and many more behaviors than just X.
Basically, what is needed is traits, mixins, components, or otherwise some form of multiple inheritance.
Usually, it is possible in Godot to have a mock ECS system by adopting some convention: go through children in the group components
and run init(self)
on each of them, for example. This is a good system, but does not solve having access to those component's properties in the editor.
What would be a good solution to this?
Solutions that are considered:
- Reproduce each of the exported vars of X in each of A, B, and C, and use setters and getters
- pros: no need for editable children
- cons: need to make sure to keep children's exported vars and parent's exported vars in sync. A lot of duplication, no DRYness at all
- Have a script that copies all
export
ed properties of X in A, B, and C. Results in the same as #1 above
- pros: properties stay in sync
- cons: need some form of robust
.gd
file parsing, .tscn
parsing, and maintenance outside of the actual game project
- Add X as a child in each scene where A, B, or C are needed
- pros: no need for editable children
- cons: visual noise in the scene tree, specially if there are more behaviors than just X. Easy to forget. Lots of repeated hand movement (looking for the node, adding the node...). Need to go back and add new children to all instances of A if now A needs X and Y.
None of these solutions seems satisfactory. Having at least Interfaces would help solution #1, but there aren't any in Godot.