Godot: Inheriting custom class causes "Too few arguments for _init() call. Expected at least 1" regardless of number of arguments.

Created on 21 Feb 2019  路  2Comments  路  Source: godotengine/godot

Godot version:
3.1-custom-build 8908bdc7f2fd002d71e836ef4f9c16fdfdc69e99

OS/device including version:
Windows 10

Issue description:
Extending a custom class, and overriding _init() causes error: "Too few arguments for _init() call. Expected at least 1", regardless of how many arguments _init() actually has.

Steps to reproduce:

class Parent:
    func _init(param1):
        self.param1 = param1

class Child extends Parent:
    func _init(param1, param2):
        .init(param1)
        self.param2 = param2

Minimal reproduction project:
inherited_custom_class_override_init_error.zip

archived

Most helpful comment

Interesting. That seems to work, but is very unintuitive and not pythonic at all.

All 2 comments

You need to do func _init(p1,p2).(p1): to call the parent class constructor.

See https://docs.godotengine.org/en/3.0/getting_started/scripting/gdscript/gdscript_basics.html#class-constructor

Interesting. That seems to work, but is very unintuitive and not pythonic at all.

Was this page helpful?
0 / 5 - 0 ratings