Skip to content

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

By Eduardo Orellana · Updated

The dictionary has no such key. stats["mp"] on a dictionary that only holds "hp" stops with Invalid access to property or key 'mp' on a base object of type 'Dictionary'. Read it with stats.get("mp", 0), which returns the default for a missing key, or test stats.has("mp") first.

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

Reading a Dictionary with [] asks it for the key, and a missing key is an error rather than null. The VM reports the key and the base type.

Dot access reads a key too: stats.mp on a Dictionary looks up the key "mp" and fails with the same message when it is missing.

Keys are compared by type as well as value: the String "1" and the int 1 are different keys, so a dictionary filled with int keys and read with a String key fails here.

More on this: How to get the current date and time in Godot 4: the Time singleton

Reproduce it

A stats dictionary with hp, read for mp.

GDScript
extends Node

func _ready() -> void:
	var stats = {"hp": 10}
	var key = "mp"
	print(stats[key])
	print("after")

What Godot 4.7.2 prints

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

SCRIPT ERROR: Invalid access to property or key 'mp' on a base object of type 'Dictionary'.
   at: _ready (res://answers/invalid-access-to-property-or-key-on-dictionary/repro.gd:6)
   GDScript backtrace (most recent call first):
       [0] _ready (res://answers/invalid-access-to-property-or-key-on-dictionary/repro.gd:6)

Fix it

Read with a default, or check the key first.

GDScript
extends Node

func _ready() -> void:
	var stats = {"hp": 10}
	var key = "mp"
	print(stats.get(key, 0))
	if stats.has(key):
		print(stats[key])
	else:
		print("no ", key)

What the fixed script prints

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

0
no mp

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 access to property or key 'position' on a base object of type 'null instance' in Godot 4

Prompt
My Godot 4 project prints this error: "Invalid access to property or key 'mp' on a base object of type 'Dictionary'.". Find where it comes from and fix it. The dictionary has no such key. stats["mp"] on a dictionary that only holds "hp" stops with Invalid access to property or key 'mp' on a base object of type 'Dictionary'. Read it with stats.get("mp", 0), which returns the default for a missing key, or test stats.has("mp") 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 get index 'mp' (on base: 'Dictionary'). The cause and the fix are the same.

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

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 1128, the message, Dictionary.get in the class reference.

Questions

Does writing to a missing key fail too?
No. stats["mp"] = 5 adds the key. Only reading a missing key with [] or dot access is an error.
Why does my JSON dictionary say the key is missing?
JSON.parse_string turns every number into a float and every key into a String. A key you wrote as 1 comes back as "1".

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

Download Flockbay free