Script inherits from native type 'KinematicBody2D', so it can't be instanced in object of type: 'Sprite' How to solve it

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

I am learning to devolop a 2d game. While coding I am getting these errors. I tried every way to solve it. but I can’t. I searched on google but can’t find a solution. I am stuck with this.

:bust_in_silhouette: Reply From: haydenv

Check the top of the script and make sure the first line is “extends Sprite”.

If you originally made the script on a KinematicBody2D and later put the script on a Sprite, then the top line will still be “extends KinematicBody2D” but it needs to be changed to “extends Sprite”.

:bust_in_silhouette: Reply From: codelyok13

I recommend you use composition versuses inheritance.

Basically, create a sprite node and give it a kinematic2d child or just have a node and have it have a sprite and kinematic2d as children. By doing this you can have both thing in a single node without needing to inherit two scripts.

Code speaks through signals or direct calls
Sprite → Sprite Script
→ Kinematic2d → Current Script

Node2D → Connecting Kinematic and Sprite or Other Stuff
→ Kinematic2d
→ Sprite