godotengine / godotengine/godot

Slider gets wrong initial value with fractional range

Open
#89,252 8 comments 2 reactions 0 assignees View on GitHub
bug regression topic:editor topic:gui
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

4.3dev4

### System information

Ubuntu 23.04 23.04 - X11 - Vulkan (Forward+)

### Issue description

With some combination of min/max/step/value of a slider, the actual retrieved initial value from GDScript is not equal to the value set in the editor.

### Steps to reproduce

The below table lists some combinations of the properties. All other properties remain in default except for `step=0.1` for all experiments. It shows that for some combinations the actual value isn't what is expected.

min | max | value | actual initial value
---- | ---- | ---- | ---- |
0 | 100 | 0 | 0
0 | 1 | 0 | 0
0 | 0.5 | 0 | 0
-1 | 1 | 0 | 0
-0.9 | 1 | 0 | 0.1
-1.1 | 1 | 0 | -0.1
-1.4 | 1 | 0 | -0.4
-1.7 | 1 | 0 | 0.3
-1.7 | 5 | 0 | 0.3
-1.7 | 0 | 0 | 0

For what I have seen so far at least the following pattern always goes wrong:
`step` = 0.1, `value` = 0 (default), `min value` < 0 and is fractional, `max value` > 0

One case that causes error.
![Screenshot_20240307_234939](https://github.com/godotengine/godot/assets/9572364/c34f9750-72e9-4873-a654-8715af77b4a7)

How it looks like in the editor (value = 0) and how it looks like in runtime (value = 0.5)
![Screenshot_20240307_235004](https://github.com/godotengine/godot/assets/9572364/52a4318d-4825-48a6-a49f-0f4c71751ce6)

The issue seems disappear if I explicitly set `value` to something that is not the default 0 in the editor, but this is not a workaround if I truly want the initial value to be 0.

### Minimal reproduction project (MRP)

[slider_bug.zip](https://github.com/godotengine/godot/files/14526658/slider_bug.zip)

I found that after opening the project, the `value` property is automatically set to 0.5 even though the packed scene does not say that. Reset it to 0 and run the scene and one can see that the value is still 0.5.

Contributor guide

Open the contributing guide

Research direction

Start with the attached minimal reproduction project and reproduce the Slider property combinations using step=0.1, especially fractional negative min values with value=0. Compare the editor's value with the runtime value; done means the initial runtime value matches the value saved in the editor, including 0.

Written by the indexing model from the issue text.

Assessment

Domain
game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.