Loading scene in Godot 4 with gdscript

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Raging_Panda

Hey Guys,

This is how I was loading a scene in my game in Godot 3.
In Godot 4 this currently gives me the error:

Invalid Call. Nonexistent function ‘instance’ in base ‘PackedScene’

Any idea what has changed in GDscript 2.0 because I use this syntax a lot

var scene
if dummy_mode == true:
	scene = load("res://scenes/Dummy_serial_interface.tscn")
else:
	scene = load("res://scenes/Serial_interface.tscn")
var scene_instance = scene.instance()
scene_instance.set_name("Serial_interface")	
self.add_child(scene_instance)
:bust_in_silhouette: Reply From: Raging_Panda

Well thanks to the lovely documentation in there now I see it is

scene.instantiate()

“lovely” changing a function to instantiate for no reason. so dumb…

godotbruhwhy | 2023-04-23 01:55

This change makes a lot of sense to me. Thanks for pointing it out! I’m not trying to grab an instance, I’m trying to instantiate one!