Skip to content

Invalid access to property or key 'position' on a base object of type 'null instance' in Godot 4

By Eduardo Orellana · Updated

The node you reached for was not found. In Godot 4 a $Player or get_node_or_null("Player") that finds no node gives you a reference to nothing, and reading .position from it fails with this error. Fix the node path, or the scene, so the node exists where the path says.

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

GDScript compiles player.position to a named property read, and the virtual machine asks the value in player for position. Here player holds an Object reference that points at no object, so there is nothing to ask, and the function stops with this error.

'null instance' is how Godot names that case: the variable's type is Object, but no object is behind it. That is what $Player and get_node() return when no node sits at that path, after printing their own Node not found error, and what get_node_or_null() returns without printing anything.

A variable that was never assigned at all reads as 'Nil' instead, and an object that existed and was freed reads as 'previously freed'. Both have their own pages, linked below.

Read the first error in the output, not the last: Node not found names the path that failed and the node it was relative to.

More on this: Cannot call method '…' on a null value in Godot 4

Reproduce it

An @onready variable filled from $Player, in a scene that has no child named Player. The scene is one Node with this script.

GDScript
extends Node

@onready var player: Node2D = $Player

func _ready() -> void:
	print(player.position)
	print("after")

What Godot 4.7.2 prints

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

ERROR: Node not found: "Player" (relative to "/root/Repro").
   at: get_node (scene/main/node.cpp:1975)
   GDScript backtrace (most recent call first):
       [0] @implicit_ready (res://answers/invalid-access-to-property-or-key-on-null-instance/repro.gd:3)
SCRIPT ERROR: Invalid access to property or key 'position' on a base object of type 'null instance'.
   at: _ready (res://answers/invalid-access-to-property-or-key-on-null-instance/repro.gd:6)
   GDScript backtrace (most recent call first):
       [0] _ready (res://answers/invalid-access-to-property-or-key-on-null-instance/repro.gd:6)

Fix it

The same script in a scene that has a Node2D child named Player, so $Player finds it. If the node lives elsewhere, the path must say where: $"../Player" for a sibling, or %Player for a node marked Access as Unique Name in its scene.

More on this: How to get the class name of a node in Godot 4: get_class() and get_global_name()

GDScript
extends Node

@onready var player: Node2D = $Player

func _ready() -> void:
	print(player.position)
	print("after")

What the fixed script prints

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

(64.0, 32.0)
after

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.

Prompt
My Godot 4 project prints this error: "Invalid access to property or key 'position' on a base object of type 'null instance'.". Find where it comes from and fix it. The node you reached for was not found. In Godot 4 a $Player or get_node_or_null("Player") that finds no node gives you a reference to nothing, and reading .position from it fails with this error. Fix the node path, or the scene, so the node exists where the path says. Then run the game headless and check that Godot's output no longer shows it.

The node was renamed or moved

$Player is a path relative to the node the script is on. Renaming the child, or moving it under another parent, breaks the path without any warning in the script editor. The Node not found line in the output names the path and the node it started from.

More on this: The "onready" keyword was removed in Godot 4: use @onready

The path is read before the node is in the tree

A $Path in a plain variable declaration, without @onready, runs when the script instance is created, before the node's children are ready. @onready waits for _ready, which is why the scripts on this page use it.

The message names the property you read

The quoted name is whatever followed the dot, so one missing node prints a different line for each property. In a scene with no Player child, player.global_position prints Invalid access to property or key 'global_position' on a base object of type 'null instance'. and player.scale prints Invalid access to property or key 'scale' on a base object of type 'null instance'. A $Button that found nothing prints Invalid access to property or key 'pressed' on a base object of type 'null instance'. for button.pressed. Each time, the Node not found line above it names the path that failed.

More on this: Cannot call method '…' on a previously freed instance in Godot 4

Setting a property on a missing node

Writing to the same reference fails with the assignment message, which also names the type of the value. With @onready var label: Label = $Missing in a scene that has no such child, label.visible = true prints Invalid assignment of property or key 'visible' with value of type 'bool' on a base object of type 'null instance'. and label.text = "Score" prints Invalid assignment of property or key 'text' with value of type 'String' on a base object of type 'null instance'. Setting a missing Sprite2D's texture to a CompressedTexture2D, the class an imported image loads as, prints Invalid assignment of property or key 'texture' with value of type 'CompressedTexture2D' on a base object of type 'null instance'. The fix is the one above: make the path find the node.

With an untyped variable, @onready var label = $Missing, label.text = 5 also reaches run time and prints Invalid assignment of property or key 'text' with value of type 'int' on a base object of type 'null instance'. With var label: Label, the parser rejects the int first with Cannot assign a value of type "int" as "String".

The same error in earlier Godot versions

Godot 4.0 to 4.2, and Godot 3, printed it as: Invalid get index 'position' (on base: 'null instance'). 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 6 October 2026, and the output above is what Godot printed, unedited.

Where the check lives in Godot's source: gdscript_vm.cpp line 1281, the message, gdscript_vm.cpp lines 62 to 72, where 'null instance' is named.

Questions

What is the difference between 'null instance' and 'Nil'?
'Nil' means the variable holds nothing at all. 'null instance' means it holds an Object reference with no object behind it, which is what a failed node lookup returns.
Why did this error used to say Invalid get index?
Godot 4.3 reworded it. Godot 4.0 to 4.2 and Godot 3 printed Invalid get index 'position' (on base: 'null instance'). for the same check.

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

Download Flockbay free