-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
String and StringName don't autoconvert and are incompatible #64171
Comments
I feel like doing something like |
For this particular case you can just do It's intended that StringNames are missing many String methods, because they are basically named pointers. Any string-based operation would require conversion to string, which is very slow. That said, Node's |
Ok thank you. But as is natural, I have hundreds of other scenarios where StringName members and return values are being used. I gave two.
It's slower in GDScript. We now have to do explicit conversions through the language processor, when it should be implicit and done in C++. We cannot access pointers, so TBH they don't concern us as GDScript users. What we as users experience is, in GD3: using Strings and String functions and operators works everywhere in the engine. Don't think about it. The String manual page said they were unique, and passed around by reference so were already super efficient to pass or compare. Now for some unknown (and undesired by us) reason, half of all string functionality doesn't work because half of the engine String usage has been converted to another type. The manual page says there is an auto conversion, which doesn't work. Much of our string based code doesn't work. And there's no clear conversion path forward. It's a guessing game as we work out hacky code to get around the limitations of the new system. It's not just
I think I will rename this issue to the larger scope I mentioned, as concatenation is just a symptom of the bigger problem. If Godot's string philosophy changed fine, but the new solution is poorly implemented so far, broken in some cases, and has not been communicated well so far or wrongly in some cases (manual page). |
@tinmanjuggernaut Seconding, I've had to convert lots of code and along with String(int) going mysteriously away, this required me to make a lot of changes to my code. |
I am under the assumption that in general, we want users to not have to worry about StringNames and NodePaths. Instead, those should be something for experienced users to improve performance, and when less experienced users see them, they would just think "I can pass a string, it okay."
Nor are they supposed to, I'm pretty sure. You're searching if an array has something different. It doesn't work with int and float, even though those compare. This is actually super dirty as it doesn't throw an error. There has been a long discussion on RocketChat over this, with all sorts of ideas thrown around, but so far I think the most actionable one is to only keep StringNames and NodePaths as accepted types in methods, since Strings can be autoconverted without trouble there. This would get performance benefits with no regressions. When users get things like This would repair compatibility with 3.x, but break compatibility with previous betas. Edit: Perhaps scratch out NodePath. I don't know many places where they are used personally. |
Godot version
Godot 4 Alpha 13
System information
Windows 11/64, RTX 3070, Vulkan
Issue description
In GD3 we don't have to think hard about Strings. They were cheap and easy to use.
In GD4, String usage has been broken since StringNames are now used all over the engine and the two are not compatible.
ends_with
,substr
) work on StringNames because they don't auto convert and random engine functions that used to return String now return StringName.match
statement performs strict type checking unlikeif
, causing it to fail unexpectedly when comparing String to StringName #60145in
,has
, or function return values StringName comparsion missingArray.has(String)
andString in Array
#63965Because of these issues, much of our old code is broken. Moving forward, we have to care about the type we're getting back, and write in hacky explicit conversions in GDScript that may or may not work when it should be implicit and performed by C++.
Engine members and functions have no rhyme or reason as to what they return.
AnimationPlayer.animation_get_next()
, andfind_animation()
return StringName. ButSkeleton3D.get_bone_name()
returns String. Node hasname:StringName
, but alsoscene_file_path:String
.The StringName docs say,
You will usually just pass a String to methods expecting a StringName and it will be automatically converted...".
However there are a lot of instances where conversion doesn't happen.It also says
Comparing them is much faster than with regular Strings, because only the pointers are compared, not the whole strings.
However String says,Strings are reference-counted and use a copy-on-write approach, so passing them around is cheap in resources.
If they're already unique and cheap to pass around or compare, why are we going through all this trouble? Why not just drop StringName, revert back to GD3 behavior and enjoy our easier code and reference-counted, cheap Strings?The text was updated successfully, but these errors were encountered: