-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SceneTree signals for adding/removing a Node to/from a group #1259
Comments
I don't quite agree with why you want this. But w/e. Care must be taken that the signal is only emitted when the User changes groups. As hidden groups are heavily used within the editor, and some specialized nodes. And you could quickly be spammed by hundreds if not thousands of calls. |
Interestingly, I use "component" nodes which describe the "entity" traits (root node). And those components can be added to group(s). Retrieving all objects who share the same trait is a matter of |
Yes, you could, in theory, use the adding and removing of groups to trigger the adding and removing of component nodes. Though, I wouldn't necessarily recommend that since that's pretty magical and there wouldn't be a way to pass initialization logic alongside the state change. I'm just wanting to trigger function executions for |
Perhaps this would have to wait until we get an project-wide groups configuration system up and running? That way the callback would only execute for the user-defined groups configured there? Either that, or switch to a naming convention thing where groups with an underscore prefix are not added to the callbacks (that sounds much simpler and easier to work with). |
I have a case when I would like to know that a node of some group is created or added to the tree, but I don't want to set a script on the node. |
In addition to having this in SceneTree, I think Node should also have these signals: |
Describe the project you are working on:
A plugin for an ECS-like usage of nodes.
Describe the problem or limitation you are having in your project:
I use nodes and groups as a sort of state machine for system-wide process callbacks, very similar to how the Viewport node works to execute input callbacks, only, instead of each node implementing an input callback, a System node executes an operation over every node in the collection.
This works great for iterative operations like process, but not great for in-place state-change operations, e.g. going from state A to state B should trigger some logic (represented as removing group A and adding group B). I could code this logic in the individual node's script, but then I'd be sharing logic across several scripts.
Describe the feature / enhancement and how it helps to overcome the problem or limitation:
What I would prefer is if I could have a single callback that handles every node that is undergoing a group state change. Since groups are actually maintained by the SceneTree anyway, it makes sense that the SceneTree should have a signal for handling an update to its
group_map
data. Then, I could just connect to that signal and handle every node's mutation logic in a single place.Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
group_changed
signal to SceneTree with a reference to the node that was added or removed to/from the group and a string for which group was updated.SceneTree::add_to_group()
andSceneTree::remove_from_group()
._bind_methods()
function.If this enhancement will not be used often, can it be worked around with a few lines of script?:
It can be worked around, but not in an architecturally clean way. At least not without traits (though that wouldn't be optimal either since it would only work with GDScript and not other languages).
Is there a reason why this should be core and not an add-on in the asset library?:
Can't be fixed with a plugin or asset.
The text was updated successfully, but these errors were encountered: