The Godot Community Forums are back up and running! Please read the the announcement post for important information on what happened. Thanks!

What is a GDScript constructor?

mr_moonmr_moon Posts: 49Member

What exactly is it constructing and when would we use it? Does it make a new node or script somewhere?

Thanks

Comments

  • cyberealitycybereality Posts: 1,053Moderator

    Well the constructor (in other languages like C++) is the function that is called upon creating an instance of an object, where you can set default variables or initialize any data you need. I believe in GDScript this is handled by the "_ready()" function, though technically I assume the engine has a real constructor (in the engine C++ code) and the ready call happens after that.

  • To quote the Godot engine docs:
    "Note: _ready() is not the constructor; the constructor is instead _init()."

    In C# you can create a constructor by creating a function inside the class. The name of the function just needs to be the same as the class name. Google C# class constructor for more

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file