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

The index is outside the array. With the array typed and the index an int, b[i] with i = 3 on a three-element array stops with Out of bounds get index '3' (on base: 'Array'). Valid indexes are 0 to size() - 1: check i < b.size() before reading.

Source: https://flockbay.com/godot/out-of-bounds-get-index/ · Updated 2026-10-30

## What Godot is checking

When the compiler knows the base is an Array and the index is an int, it emits a typed indexed get. The VM calls the Array's own getter, which reports whether the index was out of bounds, and the VM turns that into this message with the index and the base type.

Strings take the same path. A String typed with := and read with an int index past its length prints Out of bounds get index '7' (on base: 'String').

Through an untyped variable the same read prints a different message, Invalid access of index '3' on a base object of type: 'Array'.

## Reproduce it

A typed Array of three elements, read with an int index of 3.

```
extends Node

func _ready() -> void:
	var waypoints: Array = [Vector2(0, 0), Vector2(64, 0), Vector2(64, 64)]
	var i := 3
	print(waypoints[i])
	print("after")

```

## What Godot 4.7.2 prints

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

SCRIPT ERROR: Out of bounds get index '3' (on base: 'Array')
   at: _ready (res://answers/out-of-bounds-get-index/repro.gd:6)
   GDScript backtrace (most recent call first):
       [0] _ready (res://answers/out-of-bounds-get-index/repro.gd:6)
```

## Fix it

Wrap the index for a path that loops, or stop at the end for one that does not.

```
extends Node

func _ready() -> void:
	var waypoints: Array = [Vector2(0, 0), Vector2(64, 0), Vector2(64, 64)]
	var i := 3
	print("looping: ", waypoints[i % waypoints.size()])
	print("clamped: ", waypoints[mini(i, waypoints.size() - 1)])

```

## What the fixed script prints

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

looping: (0.0, 0.0)
clamped: (64.0, 64.0)
```

## 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: "Out of bounds get index '3' (on base: 'Array')". Find where it comes from and fix it. The index is outside the array. With the array typed and the index an int, b[i] with i = 3 on a three-element array stops with Out of bounds get index '3' (on base: 'Array'). Valid indexes are 0 to size() - 1: check i < b.size() before reading. Then run the game headless and check that Godot's output no longer shows it.
```

## Reading a String by character

text[i] on a String typed with := reads one character. An index equal to text.length() is already past the end, and prints this message with base 'String'.

```
var text := "abc"
for i in text.length():
	print(text[i])

```

## The same error in earlier Godot versions

Godot 3.6 printed it as: Invalid get index '3' (on base: 'Array'). 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 1200, the message](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_vm.cpp#L1200), [gdscript_vm.cpp lines 1180 to 1203, the typed indexed get](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_vm.cpp#L1180-L1203).

## Questions

### What is the difference from Invalid access of index?

Only what the compiler knew. A typed Array with an int index gives Out of bounds get index; an untyped variable gives Invalid access of index '3' on a base object of type: 'Array'.

### Is there a safe get that returns null instead of an error?

Not on Array. Check size() first, or use a Dictionary, whose get(key, default) returns the default for a missing key.

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/), [Invalid assignment of index '…' (on base: 'Array') with value of type '…' in Godot 4](/godot/invalid-assignment-of-index-on-array/), [Unable to obtain iterator object of type 'Object' (but was obtained on first iteration?) in Godot 4](/godot/unable-to-obtain-iterator-object-but-was-obtained-on-first-iteration/), [Invalid assignment on read-only value (on base: 'Array') in Godot 4](/godot/invalid-assignment-on-read-only-value/), [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/)
