0 votes

I was just putting a bunch of common routines into a singleton and using static typing to future-proof myself. Without checking, I assumed that the viewport sizes would be returned as type integer but it's apparently float and I got a "Narrowing conversion" warning.

Colour me surprised...

I can't think why it has to be a float. Non-integral number of pixels? So many pixels that it overflows the max number that can be held in a 64-bit Integer? Rather unlikely...

If we are to use static typing in the future for performance reasons then I guess I need to understand. Some might call it a bug but one that it might not be possible to fix without breaking backwards compatibility. Wasn't an issue before static typing. Values would get coerced when changing class but they will now raise errors.

Any thoughts?

in Engine by (35 points)

It may be the nature of the "size" property in Viewport. The size property uses a Vector2, and its "x" and "y" properties use the "float" data type. When used in a Viewport, common sense would say that they're integers. Maybe it's used for backwards compatibility, or maybe it's an oversight, though I don't really know.

1 Answer

0 votes
Best answer

I gave the following code a try and found that Vectors are always storing numbers as float :

func _ready():
    var vec= Vector2(int(0),int(5))

the previous code returned 3 (which is a the constant for a float number although I stored the values as Integers

and since get_viewport().size returns a vector , it might be the reason their type is float

by (298 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.