Skip to content

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.

Download for macOSDownload for WindowsDownload for Linux

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.

More on this: Out of bounds get index '…' (on base: 'Array') in Godot 4

Reproduce it

A constant array of limits, changed through a var.

More on this: Cannot assign a new value to a constant in Godot 4

GDScript
extends Node

const LIMITS = [1, 2, 3]

func _ready() -> void:
	var limits = LIMITS
	limits[0] = 5
	print("after")

What Godot 4.7.2 prints

Output
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.

GDScript
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

Output
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

[5, 2, 3] read-only: false
[1, 2, 3] read-only: true

Run this fix with your agent

Flockbay is the Godot editor with an AI agent built in. Paste this into Flockbay's chat, or into Claude Code or Codex connected to Flockbay over MCP: the agent finds the cause in your project, applies the fix, runs the game headless and reads Godot's output to check it.

More on this: The variable type is being inferred from a Variant value, so it will be typed as Variant in Godot 4

Prompt
My Godot 4 project prints this error: "Invalid assignment on read-only value (on base: 'Array').". Find where it comes from and fix it. 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. Then run the game headless and check that Godot's output no longer shows it.

Verified 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, Array.make_read_only in the class reference.

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.

Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.

Download Flockbay free