godotengine / godotengine/godot

export_range(x, y) number defaults to 0 when uninitialized in code even if x > 0

Open
#102,103 2 comments 2 reactions 0 assignees View on GitHub
bug discussion topic:editor topic:gdscript
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

Reproducible in 4.3.stable

### System information

Godot v4.3.stable unknown - EndeavourOS #1 SMP PREEMPT_DYNAMIC Sat, 18 Jan 2025 02:26:57 +0000 - Wayland - GLES3 (Compatibility) - Mesa Intel(R) Iris(R) Xe Graphics (RPL-P) - 13th Gen Intel(R) Core(TM) i7-1360P (16 Threads)

### Issue description

When `@export_range` is used on a variable left uninitialized or initialized to less than the first parameter in gdscript, it defaults to 0, even if the first parameter is larger than 0.

Ex:
```gdscript
@export_range(1, 2) var test_variable: float #left uninitialized, editor displays the value is 1, code prints 0
@export_range(1, 2) var test_variable2: float = 0.5 # initialized, editor still displays 1, code still prints 0
```

I've also attached a small reproduction project.

### Steps to reproduce

```gdscript
extends Node

@export_range(1, 2) var test_variable: float #left uninitialized, editor displays the value is 1, code prints 0
@export_range(1, 2) var test_variable2: float = 0.5 # initialized, editor still displays 1, code still prints 0

func _ready():
print(test_variable)
print(test_variable2)
```

Attaching to a node will have the editor display the values as 1

### Minimal reproduction project (MRP)

[bugtest.zip](https://github.com/user-attachments/files/18565636/bugtest.zip)

Contributor guide

Open the contributing guide

Research direction

Start with the attached reproduction project and the provided GDScript snippet; run it in Godot 4.3.stable and compare the editor values with the printed values. Done means uninitialized or below-range @export_range variables produce the configured lower bound in code as well as in the editor.

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.