The _process()
function is a special function in the Godot engine that is called every frame. In other words, it follows the game's framerate: if the game runs at 60 frames per second, _process()
is called 60 times per second. If the game runs at 200 frames per second, _process()
is called 200 times per second.
You can use it to perform tasks that need to happen repeatedly, like changing the position of a sprite, responding to player input, or playing animations.
This function takes a single function parameter called delta
, a decimal number representing the time that passed since the last frame. You can use delta
to make sure that your code is framerate-independent.
Here is an example of how to use the _process()
function to move a sprite to the right. This assumes that the script is attached to a 2D Node:
extends Sprite2D
var velocity = Vector2(400, 0)
func _process(delta):
position += velocity * delta
Every frame, this code adds a small value to the sprite's position
(a fraction of the velocity
value), making it move continuously.
Godot has two special functions that are called repeatedly in the game loop: _process()
and _physics_process()
. If you come from other engines, they are your update and physics update functions, respectively.
_process()
is called every frame the engine calculates, while _physics_process()
is called at a fixed rate and with a fixed delta
value.
As its name suggests, _physics_process()
is designed for physics-related code. By default, Godot calls it 60 times per second, with a fixed delta
of a sixtieth of a second. This ensures that physics calculations are always consistent, even if the framerate drops. We need this because physics bugs can occur when the time between frames changes.
Have you ever seen a game freeze for a few seconds, then have the character suddenly jump forward and move through walls? That's what happens when the framerate drops and developers don't use a function like _physics_process()
to handle physics.
So, you want to use _physics_process()
for all physics-related code, and you can use _process()
for everything else.See Also
Related terms in the Glossary