Inheritance is a process through which a class gets access to all the member functions and variables of another class. We say that it "extends" it.
In Godot, with the GDScript programming language, we can make a script extend another script or a class built into Godot using the extends keyword.
We describe the relationship between the script and the class it extends as a parent-child relationship. The parent class is the one extended by the child. The child class inherits from the parent.
For example, when you begin a script with the line extends Area2D, the parent class is Area2DArea2D, and the child class is the script.
With inheritance and this extends keyword, the child script literally extends and gets access to all the code provided by the parent class, Area2DArea2D, in this example. It's as if the script contained all the code of Area2DArea2D plus everything in the script.
There is a long chain of inheritance in the Godot game engine. For example, the Area2DArea2D node extends CollisionObject2DCollisionObject2D, which extends Node2DNode2D, which extends CanvasItemCanvasItem, which extends NodeNode, which extends RefCounted, which finally extends ObjectObject.
So, the Area2DArea2D node has access to all the functions and properties of Node2DNode2D, CanvasItemCanvasItem, NodeNode, RefCounted, and ObjectObject. You can see a fair part of it in the Inspector dock: the sections tell you which classes each property comes from.
The inheritance chain is why all the nodes in Godot have access to the add_child() and get_node() functions, among others. These two functions are part of the NodeNode class in the engine, and every node type inherits from it.
Become an Indie Gamedev with GDQuest!in GDSchool
Don't stop here. Step-by-step tutorials are fun but they only take you so far.
Try one of our proven study programs to become an independent Gamedev truly capable of realizing the games you’ve always wanted to make.