Can a child node discover that its' modulate is being affected by its parent node?

Godot Version

4.3

Question

I have a child Light2D node, which is inside a parent node.
When the modulate of the parent node changes (e.g. becomes transparent), I want the energy of the Light2D to decrease as well.
I know I can manipulate the energy from the parent node’s script, but the Light2D node is a bit like an ECS component, so I want its logic to be something like this:
When the parent node is transparent, my own light energy can become 0.
When changing the modulate of a parent node, all its child nodes are also affected. But I didn’t find a way to detect that it itself is affected by the parent node.
So, is it possible to find a node that is affected by its parent node’s modulate?

Yes we can achieve this by making a custom signal.
1- For this we need two things the inital modulate property when when first frame is loaded ( basically in _ready function)
2- Then tack them with ongoing modulate property if inital and ongoing property has some difference than emit signal and change the inital to that changed one.
3- thus every time parent modulate property is changed you are able to emit signal.

I considered this, but the change in modulate is an animation, so the signal may be emitted multiple times, and I’m a little worried that this is inefficient. Also the parent node is a component, so the signal may be emitted by many unrelated nodes. Of course I could give it a unique name, and that might not be a problem.
Actually, I think the ideal way to solve this would be if the parent’s modulate changes, some property of the child would also change, so I could “subscribe” to it.
Unfortunately, this property doesn’t seem to exist…

Answer : Basically when you instance a parent the change in modulate in that parent emit signal to it’s child and did not emit unrealted signal

I am not sure what you trying to say here. As long as I understand You want to make a signal that detect changes in parent modulate property and according to it you do some tasks with child. If am I right then the suggestion I gave you works perfectly fine.

If it does not like that. Can you elaborate it so that I can understand it in better way or you can share some screenshot of what you are doing so I come up with better solution. Happy to help you.

Maybe my screenshots of the game will help explain this.


ParentNode(Night Market Roof)
---- ChildNode(Light on the Roof)

Both parent and child nodes are components that serve different purposes.
Parent node’s role:
When the player walks behind the parent node, the parent node becomes transparent, mainly used for houses/roofs/etc. in this 2D top-down game. (This process is an animation)
Child node’s role:
Lights which are visible at certain times of the day.

Most of the time they are independent of each other, but when the light is inside the parent node (such as a light on a roof), if the player walks behind the roof, the light should also be invisible. (Changing the parent node’s modulate will not affect the energy of the child light2D node)

Currently my solution is:
ChildNode(Light) changes its energy in the _process function according to real-time conditions. So I added some extra logic in it: Change energy according to get_parent().modulate.a, the disadvantage of this solution is that it must be the first-level child of the parent node, maybe it will cause some problems in the future.

If a property is changed when the child node is affected by the parent node, I think the child node can be placed anywhere inside the parent node, which is more elegant.

If you place the child inside parent after affected by light then it does not change anything. because it is still under parent node.

You state that the modulate of the parent is changed by an AnimationPlayer.
Can you just add a track to that animation that changes the child/Light2D?

Yes we can add that.