This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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 , 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, which also has those lines at the beginning:

extends CustomNode2D
class_name Product

The structure of my ItemGenerator scene is:

ItemGenerator (Area2D)
- ItemGeneratorSprite (AnimatedSprite)
- ItemGenerator
Collision (CollisionShape2D)

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

When I instance a Product by doing:

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

I can use the methods in, but not inside, I get the following error:

Invalid call. Nonexistent function 'function_name' in base 'Area2D ('

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?

Godot version 3.3.3
in Engine by (12 points)

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.

1 Answer

0 votes

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

by (8,188 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.