Virtual Function
2025/12/27
- Type
- Learning Resource
- Format
- Glossary Article
- Version
- General
- Subject Tags
- Created
- Updated
- 2026/02/16
- 2025/12/27
Godot provides some functions that are empty and do nothing by default. They exist only to override them, and they don't do anything otherwise. We call these virtual functions.
For example, the _ready() and _process() functions are virtual. They are defined in the engine and don't do anything by default.
Virtual functions allow Godot to assume that every node has these functions, and the engine can call them without checking if they exist. If a node doesn't have a script in your project, internally, Godot will still call these functions blindly, and nothing will happen. If the node has a script that overrides these functions, your code will run.
Some of the most used virtual functions are:
_ready(): Called when the node is added to the scene tree._process(delta): Called every frame._physics_process(delta): Called every physics frame. Physics runs at a fixed frame rate to ensure consistency in the simulation._input(event): Called for every input event._unhandled_input(event): Called for every input event not consumed by _input()._enter_tree(): Called when the node enters the scene tree, before _ready().GDScript doesn't exactly have virtual functions, but you can create your own virtual functions by creating empty functions that you expect to be overridden. For example, here's a class named Unit with a virtual function take_damage():
class_name Unit
var health := 10
func take_damage(_amount: int) -> void:
passIn a class that extends the Unit class, you can override the take_damage() function to make it do something. Here, it reduces the health of the unit by the given amount and ensures the health doesn't go below zero:
class_name Player extends Unit
func take_damage(amount: int) -> void:
health = max(0, health - amount)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…