-
-
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 a Node.node_added
signal/method to detect the addition of children and subchildren nodes
#2544
Comments
Related to/duplicate of #627? |
@Calinou It's not duplicate, this issue talks about the node of a group is added in the tree, my proposal talks about the node that is added to another node as child/subchild, the use cases from this proposal and mine are different. |
Closely related to #724 (this proposal suggests adding a method as an alternative), but could be considered a duplicate for organization purposes. The use cases seem to be different, though.
See my proposed solution to this (and current workaround): godotengine/godot#43729. |
C# can't override add_child or remove_child and I would like to use a signal like this for laying out children in a grid. |
Node.node_added
signal/method to detect the addition of children and subchildren nodes
I have a use case for this. I'm working on an inventory system. It works by having items directly parented to it. When an item is "picked up" I need to invoke a method in the item. My current workaround is to call this method manually. It would be great to have the inventory do this automatically using |
Describe the project you are working on
A project based of components added to a node
Describe the problem or limitation you are having in your project
In my project, a custom node can have multiple components that describes it's behaviour, each component can be added as the direct child or subchild of this node. I need a way to easily tell this node that a child or subchild node was added, even if not inside tree yet, something that
SceneTree.node_added
cannot do.Describe the feature / enhancement and how it helps to overcome the problem or limitation
The easiest way I could think to tell the node that a direct/indirect child node was added, was to use some signal or virtual method. Something like
Node.node_added(node: Node, parent: Node)
. This could be the same to when a direct/indirect child node was removed, something likeNode.node_removed(node: Node, prevParent: Node)
, the second parameter of the signal/method would be the previous parent of the removed node. It's more interesting to be a virtual method, so it could be called even when is not added to the tree yet.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Let's say that I have this tree:
And in some point, a node called Node6 is added to Node5, and I want to tell the Node1 that this new node was added, then from SceneTree would call a notification, signal or method to tell the parents and grandparents that this node was added. The same would be if this node was removed from the tree.
If this enhancement will not be used often, can it be worked around with a few lines of script?
I'm not sure if there's a better way to do this, but it would be a nice addition to the engine IMO.
Is there a reason why this should be core and not an add-on in the asset library?
Because it requires to modify the core structure of a Node, to be able to add this behaviour.
The text was updated successfully, but these errors were encountered: