Godot: Feature request: Like the new $, but for find_node

Created on 15 Feb 2017  路  5Comments  路  Source: godotengine/godot

Just reading the devblog and I love the new $ shorthand for get_node in v3! I tend to use find_node more because it's not affected if I revise the node tree later; could we also get an alias for that?

If $Button is get_node('Button'), maybe $$Button = find_node('Button')? Doesn't have to be $$ - that was just my first thought.

archived discussion feature proposal gdscript

Most helpful comment

Personally I'm not fond of the idea. find_node should not be used that often, personally I think I've never used it as I much prefer to try to organize my scenes in a way that prevents having to find a random node by its name, and instead have predictable paths to children. Also $$Button is not particularly explicit, when using a function like find_node, it's best to stay explicit IMO.

All 5 comments

This sounds like a good idea to me. Are you ok with me implementing this @reduz?

Personally I'm not fond of the idea. find_node should not be used that often, personally I think I've never used it as I much prefer to try to organize my scenes in a way that prevents having to find a random node by its name, and instead have predictable paths to children. Also $$Button is not particularly explicit, when using a function like find_node, it's best to stay explicit IMO.

OK, if it is believed that this will lead to bad coding practices perhaps it's better to not do it.

find_node can be way slower than get_node. Don't use it when you can do the same with the later.

Closing then. Sorry @jackmakesthings but as mentioned above, find_node is slow and should be only used sparsely - I would advise you to try to organize your scenes in a way that makes it possible to use get_node whenever possible, and find_node only when you can't do without it.

Was this page helpful?
0 / 5 - 0 ratings