Is polling input frame independent?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Abgenullt

Hi,

I wonder, when the engine is updating its input state?

In Unity (Which I used before), you may miss some inputs, if you query them in Unitys “_physics_process” function, because the engine updates the input state once a frame and this is not always a tick of the physics engine.

So, I try to find out, if this is a potential problem in Godot, too. But I don’t find much information about how the game loop works internally.

Thanks,

abgenullt

:bust_in_silhouette: Reply From: wombatstampede

Ok, first of all: If you don’t want to miss a thing, then you can use event driven Input Management:

To my personal experience I would say that input actions are event driven and therefore don’t care much about screen frames. Anyway, you’re free to have a look at the source code yourself:

I didn’t go very deep but I can at least see that physics_frames are taken into account:
(from main/input_default.cpp)

bool InputDefault::is_action_just_pressed(const StringName &p_action) const {

	const Map<StringName, Action>::Element *E = action_state.find(p_action);
	if (!E)
		return false;

	if (Engine::get_singleton()->is_in_physics_frame()) {
		return E->get().pressed && E->get().physics_frame == Engine::get_singleton()->get_physics_frames();
	} else {
		return E->get().pressed && E->get().idle_frame == Engine::get_singleton()->get_idle_frames();
	}
} 

Just be aware, that this may vary by platform. (I mean, it may be different on Android/iOS)

Viele Grüße