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().
AppImage, x86_64. Ubuntu 22.04, Debian 12, Fedora 39 or newer.
Intel or AMD Chromebook, with Linux turned on.
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.
More on this: How to change scenes in Godot 4: change_scene_to_file()
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.
More on this: Can't add child '…' to '…', already has a parent '…' in Godot 4
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
More on this: In Object of type '…': Attempt to connect nonexistent signal '…' to callable '…' in Godot 4
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org
added Enemy, a Node2DRun 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.
More on this: The "onready" keyword was removed in Godot 4: use @onready
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, PackedScene in the class reference.
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.
Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.
Download Flockbay free