# Invalid assignment on read-only value (on base: 'Array') in Godot 4

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.

Source: https://flockbay.com/godot/invalid-assignment-on-read-only-value/ · Updated 2026-10-30

## 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: 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.

```
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](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.

Download Flockbay free: Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot. https://flockbay.com/download/

Related: [Invalid assignment of index '…' (on base: 'Array') with value of type '…' in Godot 4](/godot/invalid-assignment-of-index-on-array/), [Cannot assign a new value to a constant in Godot 4](/godot/cannot-assign-a-new-value-to-a-constant/), [Invalid assignment of property or key '…' with value of type '…' on a base object of type 'String' in Godot 4](/godot/invalid-assignment-of-property-or-key-on-string/), [Trying to assign an array of type "Array" to a variable of type "Array[…]" in Godot 4](/godot/trying-to-assign-an-array-of-type-to-a-variable-of-type-array/), [Every verified Godot 4 answer](/godot/), [How do I see Godot’s output and errors in Flockbay?](/docs/how-do-i-see-godots-output-in-flockbay/)
