Type Object
2025/12/27
- Type
- Learning Resource
- Format
- Glossary Article
- Version
- General
- Subject Tags
- Created
- Updated
- 2026/02/16
- 2025/12/27
The Type Object pattern is a design pattern that helps you create objects that can be plugged into another and change its type or behavior. The idea is to take data that could be part of a class (like a character's stats for example) and move it into a separate object that you can plug into that class.
Let's clarify what this means in practice. Say you're making an RPG with different character jobs.
Instead of creating separate classes for each character variation, you create a single
Jobclass and define different the different character "types" as data objects. These type objects store the properties that make each character unique, like their stats, abilities, and behavior.For example, instead of writing separate
Warrior,Mage, andRogueclasses, you create a singleJobclass and define character types as data objects that specify their health, damage, defense, and so on. The character then uses whichever type you give it.
This simple pattern is very helpful in games because it lets you create and modify content quickly. With it, game designers can define new entity types without asking a programmer to write new code. They just create a new type object with different properties.
You'll often use this pattern for character stats, character jobs or classes, and for pickup items. It's also used a lot in Godot, with its built-in resource system: you can easily plug a material, a shader, a mesh into different containers to change how they look. That's the type object pattern in action!
In Godot, you can use resources yourself to create type objects that can even be saved to the disk. For example:
class_name Job extends Resource
@export var job_name := ""
@export var max_health := 10
@export var attack_damage := 5
@export var defense := 2
@export var abilities: Array[Ability] = []Then you create a resource file for each job type in the Godot editor or in code. In this example, I defined the warrior job using code:
func create_warrior_type() -> Job:
var warrior_type = Job.new()
warrior_type.job_name = "Warrior"
warrior_type.max_health = 100
warrior_type.attack_damage = 15
warrior_type.defense = 8
return warrior_typeHere's an example of how you would use the job type in a character script:
class_name Character extends CharacterBody2D
@export var job: Job = null
@export var movement_speed := 100.0
var current_health := 0
func _ready() -> void:
if job != null:
current_health = job.max_health
movement_speed = job.movement_speed
func _physics_process(delta: float) -> void:
var direction := Input.get_vector("move_left", "move_right", "move_up", "move_down")
velocity = direction * movement_speed
move_and_slide()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.
Get help from peers and pros on GDQuest's Discord server!
20,000 membersJoin ServerThere are multiple ways you can join our effort to create free and open source gamedev resources that are accessible to everyone!
Sponsor this library by learning gamedev with us onGDSchool
Learn MoreImprove and build on assets or suggest edits onGithub
Contributeshare this page and talk about GDQUest onRedditYoutubeTwitter…