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

Godot Version

4.2.1

Question

Hello i got stuck in this error " Script inherits from native type ‘CharacterBody2D’, so it can’t be assigned to an object of type: ‘Node2D’ " i double check the code and try to change the node type to Node2D and change the script to " extends Node2D " but after do that i got lot of error…

1 Like

We need to know what script the error is happening in. Sorry not going to download a zip. It would be better to upload all your script files or at least the ones in question directly to github.

Changing the type of script your character is, probably isn’t the right move. But without knowing what call you get the error on, we can’t really understand what’s happening.

Based on the screenshot. class_name and your extends should be on separate lines, and your script should extend CharacterBody2D not Character

Im sorry Im beginner so i dont have enough knowledge yet… i have a script Scipt extends “CharacterBody2D” and i add a class_name to that file “Character” i do this because i need to create script for the Player “Hero” and “Enemy” so its easy to me to check and use for loop, if statement etc…

Thanks

1 Like

Your “Game” node has the hero.gd script, but “Game” is a Node2D, not a CharacterBody2D. I would bet you do not want the root node “Game” to be a hero.gd, probably just a script mix-up

3 Likes

Ohhh i see thank you. Finally, I didn’t check that, that’s why, I misplaced the scrip, that’s its “game_manager.gd” i accidentally changed it, that’s why the error occurred.

2 Likes

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