Why is my scene not extending from a custom class?

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

Hi, I just started learning godot, and ran into an issue. I have three scenes which all (in their scripts) inherit from a class I made (CustomNode2D, which in itself extends from Node2D. The scenes will share many methods, with slight changes, that’s why I’d rather use inheritance here.

My ItemGenerator.tscn scene is linked to the script ItemGenerator.gd , which has this at the beginning:

extends CustomNode2D
class_name ItemGenerator

And I can properly use the methods lying in “CustomNode2D”, so this works fine. However, I have a different scene, Product.tscn, which uses the script Product.gd, which also has those lines at the beginning:

extends CustomNode2D
class_name Product

The structure of my ItemGenerator scene is:

ItemGenerator (Area2D)

  • ItemGenerator_Sprite (AnimatedSprite)
  • ItemGenerator_Collision (CollisionShape2D)

The structure of my Product scene is exactly the same, just with different names.

ISSUE
When I instance a Product by doing:

var item = load(‘res://Scenes/Product.tscn’).instance()

I can use the methods in Product.gd, but not inside CustomNode2D.gd, I get the following error:

Invalid call. Nonexistent function ‘function_name’ in base ‘Area2D (Product.gd)’

So it seems like the issue is the inheritance isn’t working for this scene, but it does for the other, why could this be?

If everything is spelled correctly, could you check if your issue is similar to this one? The source of this issue was that one of the scripts contained an _init function which expected arguments but was not provided with any, reported in version 3.2.1.

CardboardComputers | 2022-03-14 14:06

:bust_in_silhouette: Reply From: Inces

How is ItemGenerator Area2D if it inherits Node2D in the end ? Aren’t You trying to call Area2D methods ?