A script is associated with a specific node. The script must extend that node type. So, at the top of the script, this line must match the node-type the script is attached to:
extends Node2D
If you have a script with that extends Node2D (like above), attached to (for example) a CanvasLayer node, you’ll get this error:
Script inherits from native type 'Node2D', so it can't be instanced in object of type: 'CanvasLayer'
So, to fix it, change the extends XXX line in the script to match the node-type the script is attached to.
I’ve arrived here by search engine, looking for a solution for: Script inherits from native type 'Reference', so it can't be instanced in object of type: 'Object'.
In my case, it was a serialized object in a user config file (e.g. user://example.ini). I’ve prepared a working example of such a serialized object that should allow the reproduction of the error (The section doesn’t have to be “Main”, I’m including it here for clarity):
In order to trigger the error with the above object, it’s enough to paste the following into the script of a new project and run it (provided the object is already in the config file):
extends Spatial
func _ready():
var cfg = ConfigFile.new()
cfg.load("user://example.ini")
On Linux at least, assuming your project’s name is “Splarploinks” and the user config file name is “example.ini”, its path should be ~/.local/share/godot/app_userdata/Splarploinks/example.ini.