# Invalid call. Nonexistent function 'instance' in base 'PackedScene' in Godot 4

PackedScene.instance() is called instantiate() in Godot 4. var enemy = scene.instance() fails with Invalid call. Nonexistent function 'instance' in base 'PackedScene'; write var enemy = scene.instantiate() and add the result to the tree with add_child().

Source: https://flockbay.com/godot/nonexistent-function-instance-in-base-packedscene/ · Updated 2026-10-30

## What Godot is checking

The call is resolved when it runs: the variable holds a PackedScene, and PackedScene has no method named instance in Godot 4, so the function stops and Godot names the method and the class it looked in.

It is a runtime error: the script loads, and the error appears only when the line runs, as the output below shows. On Godot 4.7.2 that holds even when the variable is typed, var scene: PackedScene, so the first time you hear about it is the first time that code runs.

## Reproduce it

A scene packed in code, then made into nodes with the Godot 3 call. In a project the scene usually comes from preload("res://enemy.tscn"); the call fails the same way.

```
extends Node

func _ready():
	var root = Node2D.new()
	root.name = "Enemy"
	var scene = PackedScene.new()
	scene.pack(root)
	var enemy = scene.instance()
	add_child(enemy)
	print("after")

```

## What Godot 4.7.2 prints

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

SCRIPT ERROR: Invalid call. Nonexistent function 'instance' in base 'PackedScene'.
   at: _ready (res://answers/nonexistent-function-instance-in-base-packedscene/repro.gd:8)
   GDScript backtrace (most recent call first):
       [0] _ready (res://answers/nonexistent-function-instance-in-base-packedscene/repro.gd:8)
WARNING: 1 RID of type "CanvasItem" was leaked.
   at: _free_rids (servers/rendering/renderer_canvas_cull.cpp:2733)
WARNING: 1 ObjectDB instance was leaked at exit (run with `--verbose` for details).
   at: cleanup (core/object/object.cpp:2536)
```

## Fix it

instantiate(), then add the new node to the scene tree.

```
extends Node

func _ready() -> void:
	var root := Node2D.new()
	root.name = "Enemy"
	var scene := PackedScene.new()
	scene.pack(root)
	root.free()
	var enemy := scene.instantiate()
	add_child(enemy)
	print("added ", enemy.name, ", a ", enemy.get_class())

```

## What the fixed script prints

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

added Enemy, a Node2D
```

## 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 project was written for Godot 3 and Godot 4 stops on this: "Invalid call. Nonexistent function 'instance' in base 'PackedScene'.". Port every use to Godot 4. PackedScene.instance() is called instantiate() in Godot 4. var enemy = scene.instance() fails with Invalid call. Nonexistent function 'instance' in base 'PackedScene'; write var enemy = scene.instantiate() and add the result to the tree with add_child(). Then run the game headless and check Godot's output for errors.
```

## 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 6 October 2026, and the output above is what Godot printed, unedited.

Where the check lives in Godot's source: [gdscript_vm.cpp line 163, the message](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_vm.cpp#L163), [PackedScene in the class reference](https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/PackedScene.xml).

## Questions

### What replaced instance() with an edit state, like instance(PackedScene.GEN_EDIT_STATE_INSTANCE)?

instantiate() takes the same edit-state argument: scene.instantiate(PackedScene.GEN_EDIT_STATE_INSTANCE). Games rarely need it; it is for editor plugins.

### Why does it say 'instatiate' after I renamed the call?

That is a typo of instantiate(), and Godot reports it the same way: scene.instatiate() prints Invalid call. Nonexistent function 'instatiate' in base 'PackedScene'. Check the spelling: instantiate has an n after insta.

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: [How to change scenes in Godot 4: change_scene_to_file()](/godot/how-to-change-scenes-in-godot-4/), [Invalid call. Nonexistent function '…' in base 'Nil' in Godot 4](/godot/nonexistent-function-in-base-nil/), [How to tween in Godot 4: create_tween() and tween_property()](/godot/how-to-tween-in-godot-4/), [How to connect signals in code in Godot 4: signal.connect(callable)](/godot/how-to-connect-signals-in-code-in-godot-4/), [Every verified Godot 4 answer](/godot/), [Does Flockbay change my Godot project?](/docs/does-flockbay-change-my-godot-project/)
