godotengine / godotengine/godot

Specific exported Dictionary has null as default value

Open
#104,646 3 comments 0 reactions 0 assignees View on GitHub
confirmed discussion enhancement topic:gdscript
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

4.5 dev1

### System information

W10

### Issue description

```GDScript
@tool
extends Node

const UI_COLOR = Color("0f1f24cc")
const UI_COLOR_BG = Color("0f1f24ff")
const UI_COLOR_HEADER = Color("21292ecc")
const UI_COLOR_WINDOW = Color("21292eff")
const UI_COLOR_BG_TRANSPARTENT = Color("33e8e3ff")
const UI_COLOR_HEADER_TRANSPARTENT = Color("576163cc")
const UI_COLOR_WINDOW_TRANSPARTENT = Color("576163ff")

@export var UI_colors: Array[Color] = [
UI_COLOR,
UI_COLOR_BG,
UI_COLOR_HEADER,
UI_COLOR_WINDOW,
UI_COLOR_BG_TRANSPARTENT,
UI_COLOR_HEADER_TRANSPARTENT,
UI_COLOR_WINDOW_TRANSPARTENT,
]

@export var UI_colors_dict: Dictionary[String, Color] = {
UI_COLOR.to_html() : UI_COLOR,
UI_COLOR_BG.to_html() : UI_COLOR_BG,
UI_COLOR_HEADER.to_html() : UI_COLOR_HEADER,
UI_COLOR_WINDOW.to_html() : UI_COLOR_WINDOW,
UI_COLOR_BG_TRANSPARTENT.to_html() : UI_COLOR_BG_TRANSPARTENT,
UI_COLOR_HEADER_TRANSPARTENT.to_html() : UI_COLOR_HEADER_TRANSPARTENT,
UI_COLOR_WINDOW_TRANSPARTENT.to_html() : UI_COLOR_WINDOW_TRANSPARTENT}
```
The above code defines a few constant colors and then uses them to define an exported Array and Dictionary. The Array works correctly, the Dictionary does not initialize default value properly - it's null. Thus any value, even the default defined in the script, will be stored in the scene. You can't revert the value if the script is `@tool`. If you make it non-tool, the Dictionary gets reverted into null:

![Image](https://github.com/user-attachments/assets/7aaf1f36-4f36-46a8-850d-c571f3441dcd)

It does not matter whether the Dictionary is typed.

### Steps to reproduce

1. Attach the code above to a script
2. Try reverting colors dict

### Minimal reproduction project (MRP)

See above.

Contributor guide

Open the contributing guide

Research direction

No source file or test is named. Start by reproducing the exported Dictionary behavior with the provided GDScript in Godot 4.5 dev1, comparing it with the working exported Array and both @tool and non-tool modes. Done means the Dictionary keeps its declared default and reverting the scene value behaves correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.