What's the difference between _process and _fixed_process?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Nichefect
:warning: Old Version Published before Godot 3 was released.

The description of the two is too vague for someone inexperienced like me, so could somebody explain to me the difference between process and fixed_process, and what types of procedures are appropriate for each one?

The reason I’m asking this is because of a problem I was having with the frame rate of a project. I was using the following procedure for screen scrolling in the script for the container(root) node of a project to handle scrolling. I was running this procedure in _fixed_process:

	var t = get_viewport().get_canvas_transform()
if(player.right):
	t[2] += Vector2(-player.MOVE_SPEED*delta, 0)
if(player.left):
	t[2] += Vector2(player.MOVE_SPEED*delta, 0)
get_viewport().set_canvas_transform(t)

When doing this, the frame rate would stutter about every ten seconds. I moved the procedure to _process and the stutter went away and I’m wondering why this helped.

Also, the Player node still stutters every ten seconds, but when I moved its procedures from _fixed_process to _process the player acts all crazy and bounces around and doesn’t work properly at all.

P.S. noticed the underscores are sometimes not included in the text where I’m referring to the different process functions, but I’m gonna assume everyone knows what I’m talking about.

:bust_in_silhouette: Reply From: Freeman

As docs say:
“The delta parameter describes the time elapsed (in seconds, as floating point) since the previous call to _process(). Fixed processing is similar, but only needed for synchronization with the physics engine.”
Your problem was probably physic usage related, while using only _process and not fixed_process to properly calculate physics every 60 fps or so.

As I understand it then, any statements related to the physics of say, a kinematic body should be handled in fixed_process?

Nichefect | 2016-05-21 19:16

As I understand it then, any statements related to the physics of say,
a kinematic body should be handled in fixed_process?

Yes

genete | 2016-05-21 21:55

Thanks for the help, I’m starting to get it now. Do you have any idea why my kinematic body’s movement stutters every ten seconds?

Nichefect | 2016-05-21 22:05

No idea, without seeing the whole code.

genete | 2016-05-22 06:59

It’s probably because you are calling set_canvas_transform in the _fixed_process loop. Not a Godot expert, but usually this loop is for updating the underlying physics, _process is for updating the actual images. Putting off the slow GPU/image manipulations to the _process loop allows physics to stay accurate despite FPS drops.

jarlowrey | 2017-04-20 16:16