Class

2025/12/27

Type
Learning Resource
Format
Glossary Article
Version
General
Subject Tags
Code
Assets
All else
Copyright 2016-2026, GDQuest
Created
2026/02/16
Updated
2025/12/27

Class

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_name Player extends 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 first:

const Player := preload("player.gd")

func _on_body_entered(body: Node2D) -> void:
  if body is Player:
    # ...

Godot also allows you to create inner classes with the class keyword. Inner classes cannot be instantiated from the editor:

class Person:
  var name := ""
  var age := 0

class Superhero extends Person:
  var power := ""
Become an Indie Gamedev with GDQuest!

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.

Nathan

Founder and teacher at GDQuest
  • Starter Kit
  • Learn Gamedev from Zero
Check out GDSchool

You're welcome in our little community

Get help from peers and pros on GDQuest's Discord server!

20,000 membersJoin Server

Contribute to GDQuest's Free Library

There are multiple ways you can join our effort to create free and open source gamedev resources that are accessible to everyone!