-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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 get_descendants, get_descendant_count, get_ancestors and get_ancestor_count to Node #76674
base: master
Are you sure you want to change the base?
Conversation
Maybe this is the sort of thing that warrants a proposal so we can better assess use cases, possible workarounds, etc. |
Let's say you have a bunch of timers in a scene, nested in many nodes. for i in get_descendants():
if i is Timer:
if i.is_stopped():
prints(i.get_path(),"is not running!") |
While that's an explanation it's not really what was asked for, a proposal is important at is creates a space for discussing the things that aren't directly connected to the code or implementation, having this space of the PR be full of people discussing the "if" or general "how" about this rather than the specific "how" is unhelful |
The tabulation is still wrong in several of the files, you should use tabs not spaces, recommend using |
Is it correct now? |
Still in the |
hold on, forgot one line |
Ok, it should be correct now |
In the future I'd suggest using |
I accidentally removed the return statement.... |
} | ||
return count; | ||
} | ||
TypedArray<Node> Node::get_descendants(bool p_include_internal) const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For style there should be a line between these two functions, to make it easier to navigate and read
You're still not using correct indentation |
Where exactly? I used clang-format and there were no changes. |
That is very strange, the return line isn't indented with tabs |
For some reason the ClangFormat setting got disabled in my IDE. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I do not have any write access I'll add my thoughts since you requested and taking the opportunity to do a review for the first time
@@ -1289,6 +1289,31 @@ Node *Node::_get_child_by_name(const StringName &p_name) const { | |||
} | |||
} | |||
|
|||
int Node::get_descendant_count(bool p_include_internal) const { | |||
int count = 0; | |||
TypedArray<Node> children = get_children(p_include_internal); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure using the "get_children" function is the best way to achieve this, none of the other functions use this and instead access the children directly, see the function itself for that, not sure what the performance difference would be but that would be my suggestion
@Wolfyxon Already possible using for timer in find_children("", "Timer"):
if timer.is_stopped():
prints(timer.get_path(), "is not running!") Note So, as already mentioned, please open a proposal for this (in https://github.com/godotengine/godot-proposals (check its README)). It's not obvious such enhacement is needed in the first place, what for, etc. Proposals are for discussing such things. |
I'd also point out that there exists |
Well... the proposal would most likely get rejected since this can easily be made in GDScript with "few lines of code" static func get_descendants(node:Node,includeInternal:=false) -> Array:
var res = []
for child in node.get_children(includeInternal):
if node.get_child_count(includeInternal) > 0:
res.append_array( getDescendants(child,includeInternal) )
res.append(child)
return res |
If you're assuming it will be rejected then this PR would be as well, and ther PR should just be closed, so why not just make a proposal and see? The usefulness and necessity of this isn't really established, so it's probably not going to be merged without a proposal clarifying this, we won't just add new features or functions without knowing that they actually are needed, it's an important part of the workflow and it's important that you comply with that as a potential contributor |
Any update on how you want to proceed here? |
I will open a proposal but first I want to also make |
The documentation needs to be in alphabetical order, use |
I think |
Here to poke about that proposal again, have you lost interest in this PR? |
Node.get_descendants
returns the whole descendant tree as a single array using recursion.Node.get_descendant_count
returns the amount of descendants.Example:
Result:
[sprite,shadow,lights,light,light]