godotengine / godotengine/godot
Subsequent serializations of empty arrays get their type overwritten
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
v4.2.2.stable.official [15073afe3]
v4.3.rc2.official [3978628c6]
v4.7.dev3.official [60fff00a6]
### System information
Ubuntu
### Issue description
```
E 0:00:00:0552 assign: Cannot assign contents of "Array[int]" to "Array[String]".
Method/function failed.
core/variant/array.cpp:276 @ assign()
```
### Steps to reproduce
```swift
@tool
extends Control
var prop_a: Array[int]
var prop_b: Array[String]
func _get_property_list() -> Array[Dictionary]:
var properties: Array[Dictionary]
properties.append({
"name": "prop_a",
"type": TYPE_ARRAY,
"hint": PROPERTY_HINT_TYPE_STRING,
"hint_string": "%d:" % [TYPE_INT]})
properties.append({
"name": "prop_b",
"type": TYPE_ARRAY,
"hint": PROPERTY_HINT_TYPE_STRING,
"hint_string": "%d:" % [TYPE_STRING]})
return properties
```
Using `_get_property_list` we add two arrays of different types.
However, when these properties are serialized in the scene file, then `prop_b` will for some reason be given the same type as `prop_a`:
```
prop_a = Array[int]([])
prop_b = Array[int]([])
```
This then leads to the above error message at runtime. This appears to only happen when one or both of the arrays are empty.
Even when providing an empty array as default value via `_property_can_revert()` and `_property_get_revert()`, the empty array still gets serialized. Although perhaps that is a different bug.
### Minimal reproduction project (MRP)
[godot_4_property_array_bug.zip](https://github.com/user-attachments/files/16501163/godot_4_property_array_bug.zip)
Contributor guide
Research direction
Start with the attached minimal reproduction project and the serialization behavior shown for prop_a and prop_b. Read core/variant/array.cpp around assign() at line 276, then trace the scene serialization path for empty typed arrays. Done means separately typed empty arrays remain Array[int] and Array[String] after serialization and no assignment error occurs at runtime.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100