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.
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.
Reproduce it
A stats dictionary with hp, read for mp.
extends Node
func _ready() -> void:
var stats = {"hp": 10}
var key = "mp"
print(stats[key])
print("after")
What Godot 4.7.2 prints
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.
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
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
0
no mpThe 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 'null instance' 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](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_vm.cpp#L1128), [Dictionary.get in the class reference](https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/Dictionary.xml).
More on this: Invalid access to property or key on a base object of type 'previously freed' in Godot 4
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".
Related
- Invalid access to property or key on a base object of type 'Nil'
- Invalid access of index on a base object of type: 'Array'
- Every verified Godot 4 answer
- Invalid access to property or key on a base object of type 'null instance' in Godot 4
- Invalid assignment of property or key '…' with value of type '…' on a base object of type 'String' in Godot 4
- Out of bounds get index '…' (on base: 'Array') in Godot 4
- How to get the class name of a node in Godot 4: get_class() and get_global_name()
- How to parse JSON in Godot 4: JSON.parse_string()
Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.
Download Flockbay free