Add a group_connect()
method to monitor signals from any nodes within a group
#5466
Labels
group_connect()
method to monitor signals from any nodes within a group
#5466
Describe the project you are working on
A project with several nodes instanced at runtime.
Describe the problem or limitation you are having in your project
Often times, the following situation occurs: A controller node creates child nodes, and connects some of their signals to itself, so that it reacts to their behaviour. However some other entity might also create the same class of child nodes, which need to be connected to the controller node. Besides the duplication of connect calls, if said entity does not have a direct reference to the controller node, it needs to somehow find it, resulting in potentially hackish and unclean solutions.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
By leveraging the functionality of groups, a function such as
group_connect(group, signal, target, method, binds, flags)
could be created, which allowstarget
to monitor the emission ofsignal
by any node withingroup
. This way, the circumstances of nodes' creation are irrelevant, as by being part of the group, they will be automatically connected to the appropriate listener.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Workflow would be almost identical to
connect()
, except it would be necessary to pass a reference to the node that is emitting the signal:This will not allow checking for the existence of a signal when connecting, as groups may contain diverse nodes, each with its own set of signals. On a technical note, this means that the hook which implements this (most likely within
scene/main/scene_tree.cpp
) will have to check whether a specific signal exists or not prior to connecting it.If this enhancement will not be used often, can it be worked around with a few lines of script?
Workarounds are feasible, but inelegant:
node_added
, check whether the node is part of a group, if yes connect it. This does not work if the node is added to the group after its creation (see Custom function to call when a node with a certain group is added #627, Add SceneTree signals for adding/removing a Node to/from a group #1259).Is there a reason why this should be core and not an add-on in the asset library?
It seems like a functionality that complements SceneTree's
call_group()
- using groups as an abstraction layer towards interacting with individual nodes.The text was updated successfully, but these errors were encountered: