C# - Delta from double to float

Godot Version 4.2 Mono

Question

in C# the _PhysicsProcess function has delta of type double, however, most Godot parameters work with float and cannot take delta because of this. I know that in System space, there is a function Convert.ToSingle(value), however I get tired of writing it every time and I just don’t like how this function visually clutters up the code. Is there any way to initially get delta as a float?

1 Like

The other way would be to create a new float variable and assign the doubles value to it.
Or simply write your own conversion function in a singleton script:

public static float ToSingle(double value)
{
     return (float)value;
}

I think you misunderstood me a little bit. So far, I’m doing pretty much what is in your code:
float _delta = (float)delta;
However, I would like to change this at the engine level, I tried to change the source code, but it is readonly, so I may have to write a C++ plugin for my idea.

Ah yeah
Thats gonna be a lot of work haha

If you want to make the process function call always pass a float instead of a double you will first have to find the process function call

If you do so, please make a post here under Ressources or sth

Good Luck!

I dont really see what the issue is here, casting like that in C# is pretty normal and you are only going to see it in your update methods anyway.

Its a slight annoyance with version 4, but ultimately it (probably) fixes more problems than it causes.

I think I’m too lazy to do this right now, or even to do it in general :0

well You Can use
(float) delta;
Top line will Convert double to float.
Hop it work :blush:

Might the undermentioned method work?

I mention it because it’s the documentation of the error which appears when I attempt to call public override void _Process(double delta) as (float delta).

Nothing at all

// CS0115.cs
namespace MyNamespace
{
    abstract public class MyClass1
    {
        public abstract int f();
    }

    abstract public class MyClass2
    {
        public override int f()   // CS0115
        {
            return 0;
        }

        public static void Main()
        {
        }
    }
}

this is not how you make child class MyClass2
should be start likeabstract public class MyClass2: MyClass1


you can do this in parent class

    public sealed override void _PhysicsProcess(double delta) => _PhysicsProcess((float)delta);
    public virtual void _PhysicsProcess(float delta){}

and now you have only _PhysicsProcess(float delta).

1 Like