How to write constructors or _init() function with parameter for c++ modules?

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

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?

:bust_in_silhouette: Reply From: sash-rc

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.