-
-
Couldn't load subscription status.
- Fork 23.5k
Add a method to construct a NodePath from a StringName #72702
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2283,6 +2283,7 @@ static void _register_variant_builtin_methods_misc() { | |
| bind_method(NodePath, slice, sarray("begin", "end"), varray(INT_MAX)); | ||
| bind_method(NodePath, get_as_property_path, sarray(), varray()); | ||
| bind_method(NodePath, is_empty, sarray(), varray()); | ||
| bind_static_method(NodePath, from_string_name, sarray("string_name"), varray()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we need to expose this function. From GDScript anyway the performance benefits are probably not that important (unless you want to test this?). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The API available through GDScript is the same as what's available through GDExtension. Also, I don't see a reason to prevent GDScript from using this method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's often brought up that we want to keep the GDScript API surface small and simple. |
||
|
|
||
| /* Callable */ | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,6 +81,13 @@ | |
| </constructor> | ||
| </constructors> | ||
| <methods> | ||
| <method name="from_string_name" qualifiers="static"> | ||
| <return type="NodePath" /> | ||
| <param index="0" name="string_name" type="StringName" /> | ||
| <description> | ||
| Constructs a NodePath from a [StringName]. This method will be faster than constructing from a String if the StringName does not contain any slashes or colons. | ||
| </description> | ||
| </method> | ||
|
Comment on lines
+84
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion, it makes no sense to expose identical constructor and static method. We can't make constructor in core for technical reasons, but in bindings we can choose what we will expose. However, I wonder if we will get the same problem with constructor in godot-cpp? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the static method is clearer, safer, and ensures we have a consistent API between C++ and GDScript. If both is not desired, then I will remove the constructor that you suggested (the second commit in this PR - glad I kept it separate 😛). EDIT: Removed, I have it saved locally if we need it back though. |
||
| <method name="get_as_property_path" qualifiers="const"> | ||
| <return type="NodePath" /> | ||
| <description> | ||
|
|
||
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 do like factory methods more than constructors, but we currently don't do this in the codebase much.
Perhaps we should go over this idea quickly in a core meeting to run it through the rest of the core team.
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.
We don't? I thought we do. The existing cases in the codebase (will be helpful information during the meeting):
Though, most of the GLTF ones came from me, so I'm biased. 😛