-
-
Notifications
You must be signed in to change notification settings - Fork 96
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 the ability to convert StringName to NodePath in C# #7602
Comments
Related godotengine/godot#72702 |
There is a point, type safety. Some methods in Godot's API may take
No, they are not the same thing. They are both pointers but in Core they are different types. If you were to use a pointer to a
There's currently no way to go from But, if godotengine/godot#72702 gets merged, I think it'd be fine to provide an explicit conversion.
Core does not support method overloads. Maybe you are suggesting that the C# generator should generate the overloads, this would result in an explosion of overloads. For example imagine a method with 2 void MyMethod(NodePath a, NodePath b); Then, we would have to generate 3 overloads to consider all possible combinations: void MyMethod(StringName a, StringName b);
void MyMethod(StringName a, NodePath b);
void MyMethod(NodePath a, StringName b); Also, this would make the conversion between Footnotes
|
Describe the project you are working on
3D Battle
Describe the problem or limitation you are having in your project
Some NodePaths are simply the property name:
So I thought I could use PropertyName:
I could cast it to string and then the implicitly conversion of string -> NodePath.
But I think you should be able to convert from StringName to NodePath without ever using a string:
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Looking at source code of StringName and NodePath I notice they are oddly equal.
I even ask myself if there any point in having both, other than just matching GDScript?
Can't StringName and NodePath have a common ancestor? I think that is possible since both are not auto-generated. And the only fields difference between then are godot_string_name and godot_node_path, but both are the exact same thing.
With that question aside I think there some solutions (In the order I like the most):
Makes somehow possible to cast StringName to NodePath. (If they have a common ancestor this would be trivial)
Make all functions that accept NodePath also accept StringName
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
If this enhancement will not be used often, can it be worked around with a few lines of script?
It can be work around by simple doing a string cast, but that will call: https://github.com/godotengine/godot/blob/fa3428ff25bc577d2a3433090478a6d615567056/modules/mono/glue/GodotSharp/GodotSharp/Core/StringName.cs#L90C32-L90C40
and then:
https://github.com/godotengine/godot/blob/fa3428ff25bc577d2a3433090478a6d615567056/modules/mono/glue/GodotSharp/GodotSharp/Core/NodePath.cs#L119
Which is not ideal
Is there a reason why this should be core and not an add-on in the asset library?
StringName and NodePath are built-in classes
The text was updated successfully, but these errors were encountered: