A class is a blueprint for creating objects. It defines a set of member variables and functions that the objects created from the class (called instances of the class) will have.Imagine a class as a recipe that outlines the ingredients and steps to prepare a meal. In this analogy, an object would be an actual meal prepared using that recipe. Multiple meals can be prepared using the same recipe, just as multiple objects can be created from the same class.So, the class is an abstract template, and the object is a concrete instance based on that template.In Godot, you can think of scenes and scene instances as classes and objects, respectively. Similarly, when adding a node to a scene, the list of nodes available to create in the dialog represents the node classes. Once you add a node to the scene, it becomes an instance of that class (a node is an object).In GDScript, you create new classes by creating a new script file. Each script is a class. Optionally, you can name a class by using the class_name keyword:
class_namePlayerextends CharacterBody2D
Then, you can use Player anywhere in the project to refer to this type of node, just like you can use Timer or Area2D.If you don't name the class, you can still refer to it, by preloading it before:
const Player :=preload("player.gd")func_on_body_entered(body:Node2D)->void:if body is Player:# ...
Godot also allows to create inner classes, with the class keyword. Inner classes cannot be instantiated from the editor:
classPerson:var name :=""var age :=0classSuperheroextends Person:var power :=""