can't be instanced in object of type: 'Sprite'

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

Hi, playing around with Godot and being frustrated very fast :wink:

Following scene-tree:
Main (Node2D)
- Concept (Sprite) saved as Scene
- labelLMB (Label)

  1. I created a Script under Concept.
  2. Created a Script under Main.
  3. Copied the text from Concept-Script to main-Script
  4. Changed the extends-statement to Node2D
  5. set Node.Script to null at Concept
  6. Deleted the Script completely
  7. Deleted all Scripts
  8. Created new Script under Main
  9. Wrote the Code again

I still get the error: Script inherits from native type ‘Reference’, so it can’t be instanced in object of type: ‘Sprite’

WTF!

Are you creating the scripts as GDScript or GDNative? You must use the GDScript. If this is not the problem, please share the project

fpicoral | 2019-01-26 15:40

I am using GDScript, so far as I can see. Is there an easy way to attach the project here?

mr.fies | 2019-01-26 16:20

Upload the folder to google docs or something and send the link. Also inform which version of Godot you are using so I can open it with the same one

fpicoral | 2019-01-26 17:16

ok hope it works, used google docs first time :wink:
https://drive.google.com/file/d/1bt2_L4J-yR-2Vro0zhZRcrgSTU07WCGS/view?usp=sharing

Godot Version 3.0.6

mr.fies | 2019-01-26 17:53

:bust_in_silhouette: Reply From: fpicoral

Thanks for sharing the project, it was very easy to find the problem looking at it:

You have in your Concept scene a Sprite as root node and it has a script which is blank.

All scripts have to have an inheritance (the extends ... part). It can be another script (put the path of the script, like extend "res://myscript.gd") or an object (extends Node).

If you don’t have an inheritance at all or it’s wrong (if you had, for example, a script in a Sprite node that extended an Area2D), it will not run and return this error.

It was not very explicit in the error message since it had no inheritance at all (this is why it was saying “inherits from native type ‘Reference’”. If you had, for example, extends Area2D in that script, the error would be “Script inherits from native type ‘Area2D’, so it can’t be instanced in object of type: ‘Sprite’”.

To solve that you can or delete the script since it has no code or add extends Sprite if you plan using this script in the future.

But:

  1. I chose Node.Script → null
  2. I deleted the script, for me there isnt a Concept.gd
  3. If I had a script, it should be shown in the top-right corner as a small icon beside the Concept-Node! Nothing shows for me, that there is still a script!

There must be somthing wrong with the ide then.

mr.fies | 2019-01-27 07:29

Here was showing a script icon in the node which leads to a empty and nameless script. After removing it, the problem was solved. You are getting this error because a node has a script and the script extends the wrong object/don’t extends nothing at all.

fpicoral | 2019-01-27 14:17

yes I understood. For me the script-icon isn’t shown as I described AND I deleted the file. So there is no other way than making a new Project. Hope such a mistake will not appear later on, when the project becomes bigger.

Actually this is a big argument not to use godot. Nevertheless I will use it, because I like Godot. But when I have such an Error again and no solution, then I will quit Godot - would be pity.

mr.fies | 2019-01-27 16:34

Before deleting it, save as it is and re upload, just to I check it out again

fpicoral | 2019-01-27 16:35

I didnt change anything, I have a buckup of that project.

mr.fies | 2019-01-27 16:37

I used the Concept.tscn in the new Project, and had the same issue.

mr.fies | 2019-01-27 16:38

Deleting the project its never a solution. If there is a problem, search in the right place and you will find the cause of it.

Imagine if the project gets bigger and you run through a problem? Would you hope to it fix itself? It’s important to learn how to debug and understand the error messages.

If the error is the same, that is the problem, you have a script without the extends ... part or it is wrong as I said before. Take a look at all your nodes with script and see if they match.

Of course, bugs with the engine can happen. If this is the case (what I doubt) you should create an issue on the GitHub page.

fpicoral | 2019-01-27 16:40

Wait 5 minutes from the time i’m posting this comment and see this video (you can’t open before because I’m uploading it rigth now) : https://youtu.be/myJWiGvZnc0

fpicoral | 2019-01-27 16:46

English is not my main language, so maybe I was not understandable. I think this is bad behaviour of Godot. I started the old Project again, and this time the field node-script was not null. I set it null several times, no script icon, the linked script-file doesnt exist.

mr.fies | 2019-01-27 16:49

Then try creating an empty script for it just with one line: extends Sprite and try again

fpicoral | 2019-01-27 16:58

Thanks for your Video that showed me where you looked for the Script-Icon. That is what confused me before, because the Script-Icon was also shown next to the Scene-Icon before.

mr.fies | 2019-01-27 16:59

Ohhh now I got what you was doing, you were removing the script for the instance of that scene but it would still crash since when Godot tries to build the original scene, it crashed.

Yeah, debugging instanciated scenes you always want to look the original one.

fpicoral | 2019-01-27 17:03

Glad you got this fixed and learned a litte more about Godot xD
If you don’t have further questions related to this problem, please set the best answer to “close” this questions on the community.

fpicoral | 2019-01-27 17:04

thanks for your help ^^

mr.fies | 2019-01-27 17:05