Add functions similar to type_convert
for every individual type that a Variant can be converted to.
#10320
Labels
type_convert
for every individual type that a Variant can be converted to.
#10320
Describe the project you are working on
A project where it is helpful to have GDScript type safety warnings/errors turned on in project settings.
Describe the problem or limitation you are having in your project
In 4.3, since the behavior of UNSAFE_CAST warning/error has been improved to recognize
variant_value as [Type]
casts as unsafe, there is now no way at all to unbox a Variant value that Godot can recognize as safe.See also the discussion here: godotengine/godot#94918
Describe the feature / enhancement and how it helps to overcome the problem or limitation
A new
type_convert
function would be added for every type that a Variant can be converted to.A new function would also be needed in the future for any additional types that can be boxed by a Variant.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
With the use of these functions, it becomes possible to convert Variant values to other typed values without the GDScript parser believing those conversions to be unsafe.
For example:
This is in contrast to the following options, which may work at runtime if the programmer is certain of the type of the value boxed by the Variant, but which are considered unsafe by Godot's type system:
If this enhancement will not be used often, can it be worked around with a few lines of script?
There is currently no workaround except to ignore Godot's type safety warnings when working with Variants.
Is there a reason why this should be core and not an add-on in the asset library?
There should be a built-in way to safely unbox Variants, rather than requiring a GDExtension for this.
The text was updated successfully, but these errors were encountered: