0 votes

If I write the module's header like this :

ClassDB::bind_method(D_METHOD("_init", "size"), &TestClass::_init);

void _init(int size) { some codes... }

And I write my gds codes like this:

var a = TestClass.new(15)

report the error when the code running :

Invalid call to function 'new' in base 'GDScriptNativeClass'. Expected 0 arguments.

By the way, If I write new() without arguments. The built-in script editor will report the error:

Too few Arguments for "_init()" call.

How should I do?

Godot version 3.3
in Engine by (12 points)

1 Answer

–1 vote

Concept of scene tree and serialization requires that objects can be created without extra dependencies on parameters in a uniform way.

Don't use constructors with parameters. Initialize your object when it's fully created.

by (1,648 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.