Let's say I have a light plant (serves as background item to provide light in a 2D platformer). This plant can have couple of different looks, but the light is always at the same spot.
So I create a new scene with root node Node2D, then put a Sprite and Light2D nodes as children. Because the plant can have couple of different looks, I create a spritesheet of how the plant can look like, and set the Sprite nodes vertical and horisontal frame counts accordingly.
Now, I can set the 'frame' property of Sprite node to be random, but I want the environment to have some consistency, so I won't do that.
I can attach a script to the root (Node2D) and export a variable that I would connect to Sprite nodes frame property, so it would look a bit like this:
export(int) var spriteFrame setget set_sprite_frame
func set_sprite_frame(f: int):
$Sprite.frame = f
The result of this is that I can set the exact look of my plant in level editor, but I cannot see that immediate change in the editor, as it just changes the middleman (spriteFrame property) of the root Node2D, and not the Sprite node's
How do I make this change visible in the editor?
One of the solutions is that I put the Sprite node as the root node, and simply put the Light2D as it's only child, but that is not the point of this question. The question is how to export child node variables that can then be seen in editor.
If you'd like me to make it a bit more logical, imagine that I need both the
frame of the Sprite node AND the
energy from the Light2D node to be exported to the root node and the changes to these properties to be visible in the editor. Now the solution of making one of these two nodes a root node falls off.