0% found this document useful (0 votes)
93 views4 pages

Class Objects & Constructors Godot GDScript Tutorial Ep 16 Godot Tutorials

The document discusses class objects and constructors in Godot GDScript. It explains that a class object is an instance of a class in Godot. It also explains that the class constructor is called when a class object is created, and is defined using the _init() method. The constructor can take arguments to initialize properties of the new class instance.

Uploaded by

Chris Lewinsky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
93 views4 pages

Class Objects & Constructors Godot GDScript Tutorial Ep 16 Godot Tutorials

The document discusses class objects and constructors in Godot GDScript. It explains that a class object is an instance of a class in Godot. It also explains that the class constructor is called when a class object is created, and is defined using the _init() method. The constructor can take arguments to initialize properties of the new class instance.

Uploaded by

Chris Lewinsky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Class Objects & Constructors | Godot GDScript Tutorial | Ep 16 | Godot Tutorials 5/8/23 4:43 PM

Courses / Introduction-To-Gdscript / Godot-Tutorials-Gdscript-16

Class Objects & Constructors | Godot GDScript


Tutorial | Ep 16

Class Objects & Constructors | Godot GDScript Tutorial | Ep 16

PREV EPISODE NEXT EPISODE

Learning Materials
 Article  Resource

https://godottutorials.com/courses/introduction-to-gdscript/godot-tutorials-gdscript-16 Page 1 of 4
Class Objects & Constructors | Godot GDScript Tutorial | Ep 16 | Godot Tutorials 5/8/23 4:43 PM

Class Objects
A class object is an instance of a class. A class object can also be referred to as a class instance, instanced object, or class object.

#Player.gd

extends Node2D

class_name Player

# class variables and functions

#Scene.gd

extends Node2D

var playerInstanceObject = Player.new()

Class Constructors
The class constructor is a particular function in which it is called every time a class object is created.

You define a class constructor using the _init() method:

#Player.gd

extends Node2D

class_name Player

var playerHealth: int

# Class Constructor
_init():
playerHealth = 100

#Scene.gd

extends Node2D

var playerInstanceObject = Player.new()


print(playerInstanceObject.playerHealth) # 100

You are also able to pass arguments into the constructor as well:

https://godottutorials.com/courses/introduction-to-gdscript/godot-tutorials-gdscript-16 Page 2 of 4
Class Objects & Constructors | Godot GDScript Tutorial | Ep 16 | Godot Tutorials 5/8/23 4:43 PM

#Player.gd

extends Node2D

class_name Player

var playerHealth: int

# Class Constructor
_init(startingHealth:int = 100):
playerHealth = startingHealth

#Scene.gd

extends Node2D

var playerInstanceObject = Player.new(200)


print(playerInstanceObject.playerHealth) # 200

Creative Common License

Class Objects & Constructors | Godot GDScript Tutorial | Ep 16 video & article by Godot Tutorials is licensed under a Creative Commons
Attribution-ShareAlike 4.0 International License .

Spread the love, share this if it helped you!

 SHARE ON TWITTER  SHARE ON FACEBOOK  SHARE ON REDDIT  SHARE WITH EMAIL

Subscribe to my Newsletter
Join our newsletter and get news in your inbox! We hate spam too, you
won't get any from me :)

 Email... SUBSCRIBE

https://godottutorials.com/courses/introduction-to-gdscript/godot-tutorials-gdscript-16 Page 3 of 4
Class Objects & Constructors | Godot GDScript Tutorial | Ep 16 | Godot Tutorials 5/8/23 4:43 PM

GODOT TUTORIALS
WEBSITE RESOURCES LEGAL OTHER

Courses Godot Privacy Policy Contact Me

Trello Cookie Policy Website Info

Github Terms & About Me


Conditions
  
Disclaimer

©2021 Godot Tutorials | Website Powered by Hugo Framework

https://godottutorials.com/courses/introduction-to-gdscript/godot-tutorials-gdscript-16 Page 4 of 4

You might also like