+1 vote

As the title says, basically how do you use _init()? As far as I can tell, this is meant to act as a constructor and that's what I'd like to use it for. In my case I'm just trying to extend a button, need to pass a few things through on creation.

Even something basic like

func _init():

Will always throw the folowing error: E 0:00:00.735 createinstance: Condition "rerror.error != Variant::CallError::CALLOK" is true. Returned: __null
<C++ Source> modules/gdscript/gdscript.cpp:121 @ createinstance()

Do I just have a bad install or something?

Godot version Godot 3.3 mono
in Engine by (13 points)

Function _init() is more like a function to call a class when it's created. It's similar to _ready(), but to my knowledge _init() is used when creating your own class.

In this documentation, it explains _init() and the basics of GDScript: https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_basics.html

Here's a previous question that might help you: https://godotengine.org/qa/86028/functions-_init-or-ready?show=86028#q86028

I'm not sure about your error code, but I'm pretty sure it has something to do with the fact that you are not calling _init() in your own custom class. With all that's said though, I'm not sure what's going on.
I hope you solve your problem.

Yeah I should've been more clear. I'm not trying to call _init() directly, I'm just trying to use it in terms of myObj.new(args). Anything with _init() defined though just immediatly throws that error on new. My current workaround has been removing the _ so that I can call myObj.new().init(args), which is just a bit janky.

Could you share a bit of your code?
And have you tried the code in the documentation?

Please log in or register to answer this question.

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 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 webmaster@godotengine.org with your username.