_unhandled_input(event) VS if Input.is_action_pressed()

Godot Version

4.3

Question

Did I get this right about godot’s input event systems?:
_unhandled_input(event):
is actually more lightweight since I’m getting notified by events when each action occurs. Adding remapping features seems a bit more complicated but is likely doable since it’s all based on checking pressed, keycodes likely by using the same overriden _unhandled_input method and storing what keycode was pressed as new mapping to an action.

_process(delta): if Input.is_action_pressed("ActionMapName"):
is slightly more heavy weight since if statements are continuously checking for input. However thanks to the use of InputMap, remapping is likely made less complicated.

Also the latter system seems based on the former.

My main concern is having to make the rebinding system myself, although not checking on every input every frame might be worth it idk.

_unhandled_input makes use of the InputMap as well.

func _unhandled_input(event: InputEvent) -> void:
    if event.is_action_pressed("jump"): # notice event. instead of Input.
        velocity.y = JUMP_VELOCITY

This sample is similar to Input.is_action_just_pressed("jump"). Each of these functions have their uses.

1 Like

ok, that’s the missing piece, makes a lot more sense haha

I guess you can call Input.is_action_just_pressed whenever you want, not necessarily every _process(). But it’s usually likely done in higher frequence.

But _unhandled_input still seems generally preferrable for a game, since it’s an overriden method that only sends events when they occur :man_shrugging:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.