Class Inheritance Godot GDScript Tutorial Ep 17 Godot Tutorials
Class Inheritance Godot GDScript Tutorial Ep 17 Godot Tutorials
Learning Materials
Article Resource
https://godottutorials.com/courses/introduction-to-gdscript/godot-tutorials-gdscript-17 Page 1 of 4
Class Inheritance | Godot GDScript Tutorial | Ep 17 | Godot Tutorials 5/8/23 4:44 PM
Class Inheritance
Class inheritance is a mechanism where you can derive a class from another class for a hierarchy of classes that share a set of attributes
and methods
# Animal.gd
extends Node2D # Inherits from the Global Node2D class
class_name Animal
# Horse.gd
extends Animal # Inherits from the Global Node2D class
class_name Horse
Animal.gd
Horse.gd
In this case, the Animal class is called a superclass, while the Horse class is called the subclass.
When a subclass inherits from a superclass, the subclass gets all the functions and class variables of the superclass.
# Animal.gd
extends Node2D # Inherits from the Global Node2D class
class_name Animal
# Horse.gd
extends Animal
# Horse class has the health variable and the getHealth() method
class_name Horse
https://godottutorials.com/courses/introduction-to-gdscript/godot-tutorials-gdscript-17 Page 2 of 4
Class Inheritance | Godot GDScript Tutorial | Ep 17 | Godot Tutorials 5/8/23 4:44 PM
# Animal.gd
extends Node2D # Inherits from the Global Node2D class
class_name Animal
# Horse.gd
extends Animal
# Horse class has the health variable and the getHealth() method
class_name Horse
# Animal.gd
extends Node2D # Inherits from the Global Node2D class
class_name Animal
# Horse.gd
extends Animal
# Horse class has the health variable and the getHealth() method
class_name Horse
https://godottutorials.com/courses/introduction-to-gdscript/godot-tutorials-gdscript-17 Page 3 of 4
Class Inheritance | Godot GDScript Tutorial | Ep 17 | Godot Tutorials 5/8/23 4:44 PM
Class Inheritance | Godot GDScript Tutorial | Ep 17 video & article by Godot Tutorials is licensed under a Creative Commons Attribution-
ShareAlike 4.0 International License .
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
GODOT TUTORIALS
WEBSITE RESOURCES LEGAL OTHER
https://godottutorials.com/courses/introduction-to-gdscript/godot-tutorials-gdscript-17 Page 4 of 4