Error for mismatching inheritance and node attaching being thrown when there is no mismatch

Godot Version

4.2.1 on Windows


I am getting an error saying "Script inherits from native type ‘RefCounted,’ so it can’t be assigned to an object of type: ‘Node2D’

The problem is that the script in question extends Node2D and is only attached to one node, which is a Node2D.

How do I fix this?


class_name Main extends Node2D

so pretty much rename class to class_name and remove the colon :

You’ll pretty much have to unident everything following that, the syntax you’re using only works for inner/subclasses.

You get the error because the engine thinks you’re defining a subclass within this script. So it is automatically falling back on refcounted as the base class for the script. So it thinks its something like:

extends RefCounted

class Main extends Node2D:

That worked.
Thank you.

1 Like

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