Skip to content
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

Added a node_added signal to the SceneTree #12224

Merged
merged 1 commit into from
Oct 20, 2017

Conversation

NathanWarden
Copy link
Contributor

This is a signal to accompany SceneTree.node_removed. It has the same behavior as node_removed only that it emits when a node is added.

Backstory, if needed:

This solves a major real world problem I'm having for a reusable library I'm writing where when an arbitrary code file, that another arbitrary developer adds to the scene, my only available options for them to use my library are:

  1. Have developer add a block of code to every code file that needs to use my library. IE: Lots of repeated code = bad programming practice (For example, I'm wanting to port a project that has about 750 code files, I would have to repeat this line in most of them)
  2. Have my library search the entire hierarchy every frame to see if their arbitrary code was on a new node added to the scene = very bad programming practice

Currently, there seams to be no good programming practice available in Godot to see when a node has been added to the scene tree, but there is one for when a node is removed, thus this pull request.

Thanks :)

@ghost ghost added this to the 3.0 milestone Oct 19, 2017
@ghost
Copy link

ghost commented Oct 19, 2017

Have you checked this issue: #11260?

@NathanWarden
Copy link
Contributor Author

NathanWarden commented Oct 19, 2017

Yes, I saw it and also discussed in the help section on Discord why node_removed exists and why this should or should not exist. Nobody responded to me about this in the engine dev section. The discussion I had leads me to the conclusion that if this should not exist, then node_removed should not exist. Not having this leads to poor programming practice, just as not having node_removed would be possible, but would lead to bad programming practice. Therefore, I believe this signal should exist.

However, the issue you mention is actually fairly unrelated because this PR would be part of the SceneTree and is a more global and arbitrary event. A node is a local/concrete thing that you can setup while you're setting up your scene. SceneTree has no idea what will be under it, nor can you access it in the editor to add such a signal.

IE. For a node being setup in a scene you can obviously keep track of when nodes are added and deleted though code and custom signals, but for certain things, like in my case, you really can't do this in the SceneTree without violating well established programming practices, as I described above. This is why I assume node_removed is there, because you can technically track when a node is deleted through code at a global scale without the node_removed signal, but you're also forced to use bad programming practices like scanning the entire tree at a regular interval and tracking the state of every node and it's children. Likewise, if I need to know when nodes are arbitrarily added by an arbitrary programmer (I'm making a 3rd party library), my only option is to force them to violate well established programming practices (lots of repeated code), or use bad programming practices myself (search the entire tree every frame). Or, I could have the person consuming my library do a few hours of setup work that could have just be automatically handled... but only if this signal exists.

Thanks :)

@akien-mga akien-mga merged commit 067fc88 into godotengine:master Oct 20, 2017
@NathanWarden NathanWarden deleted the scene_tree_added_signal branch October 20, 2017 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants