Quick answer: The value to the left of the dot is null. In target.position, Godot found that target holds nothing and so has no position to read. The name in quotes is the property you asked for; the thing that is null is whatever stands directly before it on that line. Find out why it was never assigned, or was assigned too late, and fix that. Add a null check only where having no value is a normal situation.

This is the most common runtime error in GDScript, and the message gives you less than it seems to: it names the property you wanted and says nothing about which variable was empty or why. The wording changed in Godot 4.3, so the same mistake appears online under two different messages. This guide shows both, lists the related messages for writing and calling on a null value, explains how to tell from the line which value is null, and then goes through the causes in three groups: assigned too late, never assigned, and a lookup that found nothing.

The exact error

Godot 4.3 and later, in the debugger panel and at the bottom of the script editor when the game stops:

Invalid access to property or key 'position' on a base object of type 'Nil'.

Godot 4.0 to 4.2 print the same failure as:

Invalid get index 'position' (on base: 'Nil').

In a terminal, or in the log file of a debug export, the 4.3 form looks like this:

SCRIPT ERROR: Invalid access to property or key 'position' on a base object of type 'Nil'.
   at: _physics_process (res://enemy.gd:18)

A game run from the editor pauses on the line. An exported debug build logs the error, abandons that function call and keeps running, so the same line can fail every frame. Release export templates leave out most of these runtime checks, which means a release build gives you no message at all: the script carries on with a null value or the game crashes.

What “base object of type Nil” tells you

Nil is the engine’s name for the type of null. The “base” is the expression before the dot or the square bracket. So the message reads: you asked for position on something that is null.

The quoted name locates the null for you. On a line with several dots, the null value is the expression immediately to the left of the quoted name:

var dmg = attacker.weapon.damage
# ... 'damage' on a base object of type 'Nil'  ->  attacker.weapon is null
# ... 'weapon' on a base object of type 'Nil'  ->  attacker is null

The same applies to keys. save_data["player"] on a null save_data reports 'player'.

The base is not always 'Nil'. Three variants describe an empty reference, and the difference is a useful hint about where the value came from:

Base in the messageWhat the value isWhere it usually comes from
'Nil'Plain null. Nothing was stored, or null was storedA variable that was never assigned, an @onready variable read before the node is ready, an empty @export, a function that returned nothing, Dictionary.get() on a missing key, a failed as cast
'null instance'An object reference with no object in itAn engine method that returns a node or resource and found none: a failed $Path or get_node(), get_node_or_null(), find_child(), get_first_node_in_group(), get_collider(), load()
'previously freed'A reference to an object that existed and was freedqueue_free() or free() earlier, with the variable still pointing at the old object

The first two are fixed the same way, and everything below applies to both. The third is a lifetime problem with its own guide: How to Fix “Attempt to call function on a previously freed instance” in Godot.

The same mistake in other forms

Reading a property is one of several things you can attempt on a null value. Each has its own message:

Code, with target nullGodot 4.3 and laterGodot 4.0 to 4.2
var p = target.positionInvalid access to property or key 'position' on a base object of type 'Nil'.Invalid get index 'position' (on base: 'Nil').
target.position = Vector2.ZEROInvalid assignment of property or key 'position' with value of type 'Vector2' on a base object of type 'Nil'.Invalid set index 'position' (on base: 'Nil') with value of type 'Vector2'.
target.take_damage(5), variable has a typeCannot call method 'take_damage' on a null value.Same wording
target.take_damage(5), variable is untyped and holds plain nullInvalid call. Nonexistent function 'take_damage' in base 'Nil'.Same wording
target.take_damage(5), untyped, holds an empty object referenceAttempt to call function 'take_damage' in base 'null instance' on a null instance.Same wording

If the base in your message is a real type such as 'Dictionary' or 'Node2D', the value is not null and the property or key is what is missing. For dictionaries see How to Fix “Invalid get index” on a Dictionary in Godot (Missing Keys).

What causes it

Assigned too late. The variable gets a value, and the line ran before that happened.

Never assigned. Nothing ever stored a value there.

A lookup found nothing. You asked the engine for an object and it had none to give.

Find which value is null, and why

  1. Take the quoted name and the line number from the message. The expression just left of that name is the null one.
  2. With the game paused on the error, open Debugger > Stack Trace. The panel lists the function’s local variables and the script’s members with their current values. A null one is easy to spot, and it tells you whether the variable itself is empty or something it should contain.
  3. Look at the Errors tab for anything logged earlier. A line such as Node not found: "Sprite2D" (relative to "/root/Level/Player"). or a failed resource load a few entries up is the real cause, and this error is its consequence.
  4. For a node path, switch the Scene dock to Remote while the game is paused and look at the running tree. Nodes added in code and duplicated nodes often have different names than you assumed.
  5. If the error happens once at startup and never again, suspect timing. Print from both places and compare the order:
func _ready() -> void:
    print("ready: ", name)

func use_it() -> void:
    print("use_it called, sprite is ", sprite)

Fix 1: the value is assigned too late

@onready variables are filled in just before the node’s own _ready() runs. Anything that runs earlier sees null. The setter of an exported property is a common trap, because Godot calls it while the scene is being loaded, whenever the scene file stores a value for the property:

# Broken
@onready var sprite: Sprite2D = $Sprite2D

@export var facing_left := false:
    set(value):
        facing_left = value
        sprite.flip_h = value   # sprite is still null during loading

Since this is a write, the message is the assignment form: Invalid assignment of property or key 'flip_h' with value of type 'bool' on a base object of type 'Nil'. Store the value in the setter, and apply it once the node is ready:

@onready var sprite: Sprite2D = $Sprite2D

@export var facing_left := false:
    set(value):
        facing_left = value
        if is_node_ready():
            sprite.flip_h = value

func _ready() -> void:
    sprite.flip_h = facing_left

is_node_ready() exists in Godot 4.1 and later.

Between a parent and its children, the order is children first. This child reads a parent variable one step too early:

# level.gd
@onready var spawn_point: Marker2D = $SpawnPoint

# player.gd, a child of Level
func _ready() -> void:
    global_position = get_parent().spawn_point.global_position   # spawn_point is null here

Let the parent do the work in its own _ready(), by which time every child is ready:

# level.gd
func _ready() -> void:
    $Player.global_position = spawn_point.global_position

Autoloads become ready in the order they are listed under Project > Project Settings > Globals > Autoload (a top-level Autoload tab in Godot 4.2 and earlier). If AudioManager._ready() reads Settings.config and Settings fills config in its own _ready(), move Settings above AudioManager in that list, or give config its value where it is declared so that it exists as soon as the autoload is created.

Fix 2: the value was never assigned

@export var target: Node2D

func _physics_process(_delta: float) -> void:
    var direction := global_position.direction_to(target.global_position)

A type on an exported variable restricts what can be put in the slot. It does not put anything there. Select the node in the scene where it is used, find the property in the Inspector and assign it. If the script belongs to a scene that you instance into several levels, check the instance in each level, because a reference to a node outside the scene can only be assigned there. Then make the missing assignment loud, so the next one is found at startup and not in the middle of a level:

func _ready() -> void:
    if target == null:
        push_error("%s: 'target' is not assigned in the Inspector." % get_path())
        set_physics_process(false)

Functions deserve the same suspicion as variables. A function that falls off its end returns null, and so does one that is written to return null when it finds nothing:

func find_closest_enemy() -> Node2D:
    var closest: Node2D = null
    var best := INF
    for enemy in get_tree().get_nodes_in_group("enemies"):
        var d: float = global_position.distance_squared_to(enemy.global_position)
        if d < best:
            best = d
            closest = enemy
    return closest   # null when the group is empty

The caller has to allow for that:

# Broken
func _process(_delta: float) -> void:
    look_at(find_closest_enemy().global_position)
# Fixed
func _process(_delta: float) -> void:
    var enemy := find_closest_enemy()
    if enemy:
        look_at(enemy.global_position)

Dictionary.get() behaves like that function: it returns null for a missing key unless you pass a default as the second argument. inventory.get("sword").damage fails with this error the first time the player has no sword.

Fix 3: a lookup found nothing

For a wrong node path, fix the path. Drag the node from the Scene dock into the script to get the correct one, or mark the node with Access as Unique Name and use %Name, which survives rearranging the scene. Path problems are covered in How to Fix “Node not found” / get_node Returning Null in Godot.

The other lookups return nothing as part of normal play, and for those a check is the fix, not a workaround:

# Group lookup: the player may not exist yet, or may be dead
func _process(_delta: float) -> void:
    var player := get_tree().get_first_node_in_group("player") as Node2D
    if player:
        aim_at(player.global_position)
# Cast: only some bodies are enemies
func _on_body_entered(body: Node2D) -> void:
    var enemy := body as Enemy
    if enemy:
        enemy.health -= 10
# Raycast: ask whether it hit before asking what it hit
func _physics_process(_delta: float) -> void:
    if ray.is_colliding():
        var hit := ray.get_collider() as Node
        if hit:
            print(hit.name)

A plain truth test such as if player: is enough for a value that is null. For a node that may have been freed since you stored it, use is_instance_valid(player), which is false for both null and freed objects.

load() returning nothing has a cause of its own, usually a path that differs in letter case or a file left out of the export. The log shows the failed load a line or two before this error.

Keep the checks for cases where “no value” is legitimate. A check around a variable that should always be set hides the bug and moves the symptom somewhere harder to trace: the enemy that never attacks, the label that never updates. There, fix the assignment and let the error stay loud.

How to confirm the fix

What reaches you from an exported game

This message exists only where GDScript’s runtime checks do. In a debug export it is written to the engine log each time the line runs. Bugnet’s Godot SDK reads that log file for its automatic error capture, so with File Logging enabled (it is off by default on mobile exports) the error can arrive as a report with the platform, OS and game version, and the log lines around it, including the at: line with the script and line number. Reports stack by title, and the title is the message: it contains the property name and not the script. Two unrelated bugs that both read position from a null value land in one entry, so open the occurrences and compare the script lines before closing it.

A release export prints nothing for this mistake, so there is nothing for the SDK to pick up, and a hard crash that follows is not captured as a stack trace. If you ship release builds to testers, put the check where a null would be costly and send it yourself with report_error(message, stack). What an exported game can and cannot log is covered in How to Capture Script Errors at Runtime in an Exported Godot 4 Game, and the report fields are listed in the bug report docs.

Frequently asked questions

What does Invalid access to property or key on a base object of type Nil mean?

Your code read a property or key from a value that is null. Nil is the engine's name for the type of null, and the base is the expression before the dot or bracket. The name in quotes is the property you asked for, not the thing that is null.

Is this the same error as Invalid get index on base Nil?

Yes. Godot 4.0 to 4.2 print Invalid get index 'position' (on base: 'Nil'), and Godot 4.3 and later print Invalid access to property or key 'position' on a base object of type 'Nil'. The cause and the fixes are identical.

What is the difference between Nil and null instance in the message?

Nil is a plain null, such as a variable that was never assigned or a function that returned nothing. Null instance is an empty object reference, usually from an engine method like get_node_or_null or get_collider that found no object. Both are fixed the same way.

Why is my @onready variable null?

@onready variables are assigned just before the node's own _ready() runs. Code that runs earlier sees null: _init(), a setter called while the scene loads, or a child's _ready() reading a variable of its parent, because children become ready first.

Why do I not see this error in my release export?

Release export templates leave out most of GDScript's runtime checks, so no message is logged. The script continues with a null value or the game crashes. Test with a debug export to get the message and the line.

The name in quotes is what you asked for. The null value is whatever stands directly to its left on that line, so find where that was supposed to be assigned and why it was not, before reaching for a null check.