# Invalid assignment of index '…' (on base: 'Array') with value of type '…' in Godot 4

The index is past the end of the array, and assigning to it does not grow the array. inventory[5] = item on a three-element array stops with Invalid assignment of index '5' (on base: 'Array') with value of type 'int'. Add elements with append(), or resize() the array first.

Source: https://flockbay.com/godot/invalid-assignment-of-index-on-array/ · Updated 2026-10-30

## What Godot is checking

An Array assignment by index only replaces an element that exists. When the index is past the end, the setter reports failure and the VM prints this message with the index, the base type and the type of the value.

Typed arrays name their element type in the base: an Array[int] prints (on base: 'Array[int]'). The VM's source also has an Out of bounds set index message for this case; on 4.7.2 a plain index assignment on an Array printed Invalid assignment of index, typed or not, as the run shows.

## Reproduce it

A three-slot inventory, with a value written to slot 5.

```
extends Node

func _ready() -> void:
	var inventory = [0, 0, 0]
	inventory[5] = 42
	print("after")

```

## What Godot 4.7.2 prints

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

SCRIPT ERROR: Invalid assignment of index '5' (on base: 'Array') with value of type 'int'.
   at: _ready (res://answers/invalid-assignment-of-index-on-array/repro.gd:5)
   GDScript backtrace (most recent call first):
       [0] _ready (res://answers/invalid-assignment-of-index-on-array/repro.gd:5)
```

## Fix it

Grow the array before writing past its end, or append to it.

```
extends Node

func _ready() -> void:
	var inventory = [0, 0, 0]
	if inventory.size() <= 5:
		inventory.resize(6)
	inventory[5] = 42
	print(inventory)
	inventory.append(7)
	print(inventory)

```

## What the fixed script prints

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

[0, 0, 0, <null>, <null>, 42]
[0, 0, 0, <null>, <null>, 42, 7]
```

## 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 of index '5' (on base: 'Array') with value of type 'int'.". Find where it comes from and fix it. The index is past the end of the array, and assigning to it does not grow the array. inventory[5] = item on a three-element array stops with Invalid assignment of index '5' (on base: 'Array') with value of type 'int'. Add elements with append(), or resize() the array first. Then run the game headless and check that Godot's output no longer shows it.
```

## The same error in earlier Godot versions

Godot 4.2 and Godot 3.6 printed it as: Invalid set index '5' (on base: 'Array') with value of type 'int' The cause and the fix are the same.

## 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 1023, the message](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_vm.cpp#L1023), [gdscript_vm.cpp lines 1010 to 1026, the keyed set](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_vm.cpp#L1010-L1026).

## Questions

### Why does a Godot array not grow when I assign past its end?

Index assignment replaces an existing element. Growing is a separate call: append() adds one at the end, and resize() sets the size, filling new slots with null (or the type's default in a typed array).

### What does resize() put in the new slots?

null in an untyped array, as the fix printed. A typed array such as Array[int] fills them with 0.

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 access of index '…' on a base object of type: 'Array' in Godot 4](/godot/invalid-access-of-index-on-array/), [Out of bounds get index '…' (on base: 'Array') in Godot 4](/godot/out-of-bounds-get-index/), [Invalid assignment on read-only value (on base: 'Array') in Godot 4](/godot/invalid-assignment-on-read-only-value/), [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/)
