Skip to content

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

By Eduardo Orellana · Updated

The variable is typed, as a Node2D for example, and holds null when the method is called. player.hide() with var player: Node2D never assigned stops with Cannot call method 'hide' on a null value. Assign it first, usually with @onready var player: Node2D = $Player, or check it is not null.

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

When the variable's class is known, the compiler calls the method directly instead of looking it up at run time. Before the call the VM checks that the object is not null, and stops with this message when it is.

Through an untyped variable the same mistake prints Invalid call. Nonexistent function 'hide' in base 'Nil'.

More on this: Invalid call. Nonexistent function 'instance' in base 'PackedScene' in Godot 4

Reproduce it

GDScript
extends Node

var player: Node2D

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

What Godot 4.7.2 prints

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

SCRIPT ERROR: Cannot call method 'hide' on a null value.
   at: _ready (res://answers/cannot-call-method-on-a-null-value/repro.gd:6)
   GDScript backtrace (most recent call first):
       [0] _ready (res://answers/cannot-call-method-on-a-null-value/repro.gd:6)

Fix it

Assign it from the scene, which here has a Player child, and guard calls that may come early.

GDScript
extends Node

@onready var player: Node2D = $Player

func _ready() -> void:
	if player:
		player.hide()
	print("visible: ", player.visible)

What the fixed script prints

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

visible: false

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 'Nil' in Godot 4

Prompt
My Godot 4 project prints this error: "Cannot call method 'hide' on a null value.". Find where it comes from and fix it. The variable is typed, as a Node2D for example, and holds null when the method is called. player.hide() with var player: Node2D never assigned stops with Cannot call method 'hide' on a null value. Assign it first, usually with @onready var player: Node2D = $Player, or check it is not null. Then run the game headless and check that Godot's output no longer shows it.

An exported node never set in the Inspector

@export var player: Node2D stays null until you pick a node for it in the Inspector. Every call on it fails this way until you do.

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

A get_node() that found nothing

$Player returns null when the path is wrong, after printing Node not found. Fix the path, or use a unique name (%Player).

The same error in earlier Godot versions

Godot 3.6 printed it as: Attempt to call function 'hide' in base 'null instance' on a 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 18 October 2026, and the output above is what Godot printed, unedited.

Where the check lives in Godot's source: gdscript_vm.cpp line 496, the message.

Questions

What is the difference from Nonexistent function in base 'Nil'?
Only the variable's type. A typed variable gives Cannot call method on a null value; an untyped one gives Nonexistent function in base 'Nil'. Both mean the variable is null.
Does if player: work for a freed node?
No. A freed node is not null in the same way; use is_instance_valid(player) when the node may have been freed.

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

Download Flockbay free