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 Windows

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)

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.