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

By Eduardo Orellana · Updated

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.

Download for macOSDownload for Windows

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

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.