Left operand of 'is' is a previously freed instance in Godot 4
By Eduardo Orellana · Updated
The variable still points at a node that was freed, and 'is' cannot check the type of a freed object. n is Node after n.free() stops with Left operand of 'is' is a previously freed instance. Test is_instance_valid(n) first; it returns false for a freed object.
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 a node does not clear the variables that refer to it. They keep a reference to an object that no longer exists, which Godot calls a previously freed instance.
The is operator looks up the object to compare its class. When the object is gone it cannot, and the VM stops with this message.
Reproduce it
A node freed, then type-checked with is.
extends Node
func _ready() -> void:
var enemy := Node.new()
enemy.free()
print(enemy is Node)
print("after")
What Godot 4.7.2 prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
SCRIPT ERROR: Left operand of 'is' is a previously freed instance.
at: _ready (res://answers/left-operand-of-is-is-a-previously-freed-instance/repro.gd:6)
GDScript backtrace (most recent call first):
[0] _ready (res://answers/left-operand-of-is-is-a-previously-freed-instance/repro.gd:6)Fix it
Check that the object still exists before checking its type.
extends Node
func _ready() -> void:
var enemy := Node.new()
enemy.free()
if is_instance_valid(enemy) and enemy is Node:
print("still here")
else:
print("enemy is gone")
What the fixed script prints
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
enemy is gonequeue_free() frees it at the end of the frame
queue_free() does not free a node at once: it is freed at the end of the current frame. A reference kept in an array or a variable is still pointing at it on the next frame, and an is check there fails the same way. Remove it from your arrays when you free it, or test is_instance_valid().
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 945, the message](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_vm.cpp#L945).
Questions
- Does is_instance_valid() work on null?
- Yes. It returns false for null and for a freed object, and true for an object that exists.
- Why is the variable not null after free()?
- GDScript does not clear references to a freed object. Set the variable to null yourself after freeing, or check is_instance_valid().
Related
- Invalid access to property or key on a 'previously freed' base
- Trying to cast a freed object
- Every verified Godot 4 answer
- Cannot call method '…' on a previously freed instance in Godot 4
- Invalid access to property or key on a base object of type 'null instance' in Godot 4
- Cannot call method '…' on a null value in Godot 4
- Attempted to free a RefCounted object 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