Script inherits from native type 'CharacterBody2D', so it can't be assigned to an object of type: 'Sprite2D'

Godot Version

4.5 Stable

Question

When I attach a script to a second character body 2d I have, I get the Script inherits from native type ‘CharacterBody2D’, so it can’t be assigned to an object of type: ‘Sprite2D’ error.
I can confirm the script is attached to a CharacterBody2D.
Could it be a bug? I have looked at the different threads on this, but they dont seem to help here.

Here you can see that only characterbody2d nodes have scripts attached

Note that the script for PlayerCat works fine, the error only happens when I attach a script to the Cow ChracterBody2d

Thanks

You may have attached the script to a Sprite2D on accident, or the Cow is not really a CharacterBody2D.

1 Like

Thanks for the quick reply.
I double checked again, and Cow is a ChracterBody2d

I tried something, I made the script blank and I now get a different error
Script inherits from native type ‘RefCounted’, so it can’t be assigned to an object of type: ‘Sprite2D’

In the FileSystem inside Godot, if you right-click on cow.gd and select “view owners”, what does it say?

2 Likes

Thanks, took a look at another scene in the code, and there was a rogue script that attached to a sprite in that separate scene. Not sure why the error only came up when I added a new script to the Cow CharacterBody2d, but it seems like the rogue script has been lingering there for a while and started throwing the error when I wanted to create a new script.

Did you happen to delete the script before detaching it? Ive done that before and got wild errors because of it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.