Skip to content

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

By Eduardo Orellana · Updated

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.

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

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

More on this: Invalid assignment of property or key '…' with value of type '…' on a base object of type 'String' in Godot 4

Reproduce it

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

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

GDScript
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

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

GDScript
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

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

More on this: Invalid operands 'String' and 'int' in operator '+' in Godot 4

Prompt
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'.

More on this: Invalid access to property or key '…' on a base object of type 'Dictionary' in Godot 4

GDScript
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, gdscript_vm.cpp lines 1180 to 1203, the typed indexed get.

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.

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

Download Flockbay free