Cannot call method '…' on a previously freed instance in Godot 4
By Eduardo Orellana · Updated
The node the variable points at was freed, and the variable was not cleared. n.get_name() after n.free(), with n typed as Node, stops with Cannot call method 'get_name' on a previously freed instance. Check is_instance_valid(n) before calling, and drop references when you free a node.
AppImage, x86_64. Ubuntu 22.04, Debian 12, Fedora 39 or newer.
Intel or AMD Chromebook, with Linux turned on.
What Godot is checking
Freeing an object leaves every variable that referred to it pointing at nothing. On a typed variable, the VM checks the object is still alive before a direct method call, and stops with this message when it is not.
Through an untyped variable the same call prints Invalid call. Nonexistent function 'get_name' in base 'previously freed'.
More on this: Invalid call. Nonexistent function 'instance' in base 'PackedScene' in Godot 4
Reproduce it
A typed node variable, freed, then called.
extends Node
func _ready() -> void:
var enemy: Node = Node.new()
enemy.free()
enemy.get_name()
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 'get_name' on a previously freed instance.
at: _ready (res://answers/cannot-call-method-on-a-previously-freed-instance/repro.gd:6)
GDScript backtrace (most recent call first):
[0] _ready (res://answers/cannot-call-method-on-a-previously-freed-instance/repro.gd:6)Fix it
Check the object still exists, and clear the reference after freeing it.
extends Node
func _ready() -> void:
var enemy: Node = Node.new()
enemy.free()
if is_instance_valid(enemy):
print(enemy.get_name())
else:
enemy = null
print("enemy freed, reference cleared")
What the fixed script prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
enemy freed, reference clearedVerified 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 497, the message](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_vm.cpp#L497).
Questions
- Why is my enemy freed when I used queue_free()?
- queue_free() frees it at the end of the frame. A timer, signal or array that still holds it calls it later, after it is gone.
- Is checking == null enough?
- No. Use is_instance_valid(), which is false for both null and a freed object.
Related
- Cannot call method on a null value
- Invalid access to property or key on a 'previously freed' base
- Every verified Godot 4 answer
- Left operand of 'is' is a previously freed instance in Godot 4
- Trying to cast a freed object in Godot 4
- Invalid access to property or key on a base object of type 'null instance' in Godot 4
- Invalid call. Nonexistent function '…' in base 'Nil' in Godot 4
- Invalid access to property or key on a base object of type 'Nil' 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