Best way to add a node that extends a custom class?

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

Hello!

I am trying to understand inheritance better. I’ve made a script that defines a custom class Item that extends Area2D. But, if I add a node and select Item (Item.gd) from the dropdown, rather than getting a new, scriptless node, I get a node named Item that has the Item script already attached to it.

This is undesirable to me because any time that I am adding a node, I am going to want to add a script that extends it, rather than overwriting the base class definition. As a workaround, I’ve been adding an Area2D, attaching a script, and changing the default extends Area2D to extends Item.

Is this the best method? It works fine, but it’s a pretty unintuitive workflow. I feel like I’m missing something (especially because none of the tutorials that I’ve watched on inheriting from custom classes mentions anything like this).

Thank you!!

:bust_in_silhouette: Reply From: Wakatta

Welcome to the club.
Unfortunately this is how it is as of now and there are dozens of feature requests for this exact thing already.

What’s even worse is the documentation encourages you to make custom nodes that give you the exact same results.

So until better can be done your work around is currently the best.