Invalid assignment on read-only value (on base: 'Array') in Godot 4
By Eduardo Orellana · Updated
The array is a constant, and constant arrays and dictionaries are read-only in Godot 4, even through another variable. var l = LIMITS then l[0] = 5 stops with Invalid assignment on read-only value (on base: 'Array'). Make a writable copy with LIMITS.duplicate(), or declare it with var instead of const.
AppImage, x86_64. Ubuntu 22.04, Debian 12, Fedora 39 or newer.
Intel or AMD Chromebook, with Linux turned on.
What Godot is checking
A const Array or Dictionary is made read-only when the script loads. Assigning it to a var does not copy it: arrays are passed by reference, so the var points at the same read-only array.
Writing an element checks whether the base is read-only first, and the VM stops with this message, naming the base type.
Reproduce it
A constant array of limits, changed through a var.
extends Node
const LIMITS = [1, 2, 3]
func _ready() -> void:
var limits = LIMITS
limits[0] = 5
print("after")
What Godot 4.7.2 prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
SCRIPT ERROR: Invalid assignment on read-only value (on base: 'Array').
at: _ready (res://answers/invalid-assignment-on-read-only-value/repro.gd:7)
GDScript backtrace (most recent call first):
[0] _ready (res://answers/invalid-assignment-on-read-only-value/repro.gd:7)Fix it
Change a copy, which duplicate() makes writable.
extends Node
const LIMITS = [1, 2, 3]
func _ready() -> void:
var limits = LIMITS.duplicate()
limits[0] = 5
print(limits, " read-only: ", limits.is_read_only())
print(LIMITS, " read-only: ", LIMITS.is_read_only())
What the fixed script prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
[5, 2, 3] read-only: false
[1, 2, 3] read-only: trueVerified on Godot 4.7.2
Both scripts on this page were run headless on Godot 4.7.2 (4.7.2.stable.mono.official.ed1daf0bf) on 18 October 2026, and the output above is what Godot printed, unedited.
Where the check lives in Godot's source: [gdscript_vm.cpp line 1005, the message](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_vm.cpp#L1005), [Array.make_read_only in the class reference](https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/Array.xml).
Questions
- Can I change a const Dictionary in Godot 4?
- No. Constant dictionaries are read-only the same way. Copy it with duplicate(), or declare it with var.
- Does duplicate() copy nested arrays?
- Not by default. duplicate(true) copies nested arrays and dictionaries too; without it the inner ones are shared.
Related
- Invalid assignment of index (on base: 'Array')
- Invalid assignment of property or key on a base object of type 'Nil'
- Every verified Godot 4 answer
- Cannot assign a new value to a constant in Godot 4
- Invalid assignment of property or key '…' with value of type '…' on a base object of type 'String' in Godot 4
- Invalid assignment of property or key '…' with value of type '…' on a base object of type 'Node2D' in Godot 4
- Invalid access to property or key '…' on a base object of type 'Dictionary' in Godot 4
- Trying to assign an array of type "Array" to a variable of type "Array[…]" in Godot 4
Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.
Download Flockbay free