Godot: Strings are not automatically converted to StringNames

Created on 27 Jul 2020  路  4Comments  路  Source: godotengine/godot

Godot version:

08d3d06

Issue description:

This doesn't work:

connect("body_entered", Callable(self, "entered"))

You need to use StringName explicitly:

connect("body_entered", Callable(self, StringName("entered")))

Strings used to be converted automatically.

bug gdscript usability

Most helpful comment

Note that you should be able to use &"entered" (or was it ^"entered" or @"entered"?) as a shorthand for StringName("entered"). Still, I agree it should be converted implicitly.

All 4 comments

Note that you should be able to use &"entered" (or was it ^"entered" or @"entered"?) as a shorthand for StringName("entered"). Still, I agree it should be converted implicitly.

Note that you should be able to use &"entered" (or was it ^"entered" or @"entered"?)

&"entered". I memorized as it looks like C references. And @ is for @nnotations only. :smiley:

This is mostly a problem with Variant that now treats String and StringName as different entities. So you should get used to the shorthand &"entered" to create a StringName.

This could be converted automatically when applicable so I will add that. Just note that in many cases the parser cannot infer the type, so it's not always possible to do the conversion.

Also, you don't need strings for this anymore as this:

body_entered.connect(entered)

does the same thing.

Fixed in #41359

Was this page helpful?
0 / 5 - 0 ratings