Godot Version
Godot 4.4.stable and Godot 4.3.stable
Question
I am trying to retrieve a slider’s value, but I noticed all the values I was getting from the slider were being rounded to the nearest 0.5. It was impossible to get a 0 from the slider’s value, because if the slider’s value should have been 0, it was actually 0.5.
Even if I attempt to assign a value to the slider directly via script, it will have changed the value to a nearby .5 by the immediate next line of code, which I don’t understand how that’s even possible.
I recreated and isolated the relevant code to just the parts that cause the misbehavior, and it seems that if a slider’s minimum value is a negative, fractional number, it will cause this issue, with the amount the value is rounded to being determined by the fractional amount.
It does not matter whether the slider is a VSlider or HSlider.
Is this a bug with the engine, or am I doing something wrong? If it’s me, what can I do to prevent Godot from rounding my slider’s value to some fractional amount, other than insuring that the slider’s minimum value is never set to a negative fractional amount?
Here is the code:
extends Slider
@export var max_acceleration: float = 25.0
@export var slider: Node ## The slider node is assigned via the inspector.
func _process(delta: float) -> void:
print("1---") # Dividing line
slider.min_value = -max_acceleration / 2 ## Equals 12.5
slider.value = 0.0
print(slider.value) ## Returns 0.5
slider.value = 1.0
print(slider.value) ## Returns 1.5
slider.value = -2.0
print(slider.value) ## Returns -1.5
slider.value = 0.7
print(slider.value) ## Returns 0.5
slider.value = 0.5
print(slider.value) ## Returns 0.5
print("2---") # Second dividing line
slider.min_value = -10.3
slider.value = 0.0
print(slider.value) ## Returns -0.3
slider.value = 1.0
print(slider.value) ## Returns 0.7
slider.value = -2.0
print(slider.value) ## Returns -2.3
slider.value = 0.7
print(slider.value) ## Returns 0.7
slider.value = 0.5
print(slider.value) ## Returns 0.7