.instance() not working

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

I have been searching for hours and can’t find why this gives an error. When i try instancing a scene through code it says the following “Invalid call. Nonexistent function ‘instance’ in base 'GDScript”. Have the Godot developers changed how instancing through code works? Or am i just missing something? Thanks in advance!

:bust_in_silhouette: Reply From: kidscancode

instance() is (and has always been) a method of PackedScene. You seem to be trying to call it on a script instead, which does not work.

I suspect that you’re load()ing a .gd file when you meant to load a .tscn.

Thank you so much! Sometimes it is the most silly things that get you!

Your videos got me started into Godot, and now i am making a game!
Thanks so much for the inspiration keep up your great work!

8TrumbleTun | 2021-03-17 19:50

If still this answer isn’t satisfied in Godot 4 instance() is changed with instantiate().