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

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.

Source: https://flockbay.com/godot/invalid-access-to-property-or-key-on-dictionary/ · Updated 2026-10-30

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

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

## 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).

## 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".

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 to property or key 'position' on a base object of type 'Nil' in Godot 4](/godot/invalid-access-to-property-or-key-on-nil/), [Invalid assignment of property or key '…' with value of type '…' on a base object of type 'Node2D' in Godot 4](/godot/invalid-assignment-of-property-or-key-on-node2d/), [Invalid assignment of property or key '…' with value of type '…' on a base object of type 'String' in Godot 4](/godot/invalid-assignment-of-property-or-key-on-string/), [Invalid access of index '…' on a base object of type: 'Array' in Godot 4](/godot/invalid-access-of-index-on-array/), [How to get the class name of a node in Godot 4: get_class() and get_global_name()](/godot/how-to-get-the-class-name-of-a-node-in-godot-4/), [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/)
