# Cannot call method '…' on a previously freed instance in Godot 4

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.

Source: https://flockbay.com/godot/cannot-call-method-on-a-previously-freed-instance/ · Updated 2026-10-30

## 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'.

## 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 cleared
```

## 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.

```
My Godot 4 project prints this error: "Cannot call method 'get_name' on a previously freed instance.". Find where it comes from and fix it. 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. Then run the game headless and check that Godot's output no longer shows it.
```

## 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 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.

Download Flockbay free: Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot. https://flockbay.com/download/

Related: [Invalid access to property or key on a base object of type 'previously freed' in Godot 4](/godot/invalid-access-to-property-or-key-on-previously-freed/), [Left operand of 'is' is a previously freed instance in Godot 4](/godot/left-operand-of-is-is-a-previously-freed-instance/), [Trying to cast a freed object in Godot 4](/godot/trying-to-cast-a-freed-object/), [Cannot call method '…' on a null value in Godot 4](/godot/cannot-call-method-on-a-null-value/), [Every verified Godot 4 answer](/godot/), [How do I see Godot’s output and errors in Flockbay?](/docs/how-do-i-see-godots-output-in-flockbay/)
