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.
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
A typed Node2D variable that is never assigned, then called.
More on this: Invalid assignment of property or key with value of type on a base object of type 'Nil' in Godot 4
extends Node
var player: Node2D
func _ready() -> void:
player.hide()
print("after")
What Godot 4.7.2 prints
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.
extends Node
@onready var player: Node2D = $Player
func _ready() -> void:
if player:
player.hide()
print("visible: ", player.visible)
What the fixed script prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
visible: falseAn 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 on a base object of type 'Nil' 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).
More on this: Invalid access to property or key on a base object of type 'null instance' in Godot 4
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](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_vm.cpp#L496).
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.
Related
- Invalid call. Nonexistent function in base 'Nil'
- Cannot call method on a previously freed instance
- Every verified Godot 4 answer
- Invalid access to property or key on a base object of type 'Nil' in Godot 4
- 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 'Nil' in Godot 4
- Invalid access to property or key on a base object of type 'previously freed' in Godot 4
- Cannot infer the type of "…" variable because the value is "null" in Godot 4
Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.
Download Flockbay free