Script Inherits from native type X, so it can't be instanced in object of type X.

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

Script Inherits from native type Animated Sprite, so it can’t be instanced in object of type Sprite.

I’m starting to learn Godot and I decided to recreate a game from scratch, I came across this error and can’t find a solution.,

1 Like
:bust_in_silhouette: Reply From: jgodfrey

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.

:bust_in_silhouette: Reply From: Aziroshin

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):

[Main]

example=[ Object(Object,"script":Object(GDScript,"resource_local_to_scene":false,"resource_name":"","script/source":"")]

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.

Setup info:

  • Godot 3.4
  • Ubuntu 20.04