Godot Version
Godot 4.3
Question
When awaiting a signal in a coroutine and that signal is emmited by checking an InputEvent, Input.is_action_just_pressed() will return true for the action associated with the event for two consecutive physics frames. Below is the code used to check:
func _input(event):
print(event)
if event is InputEventKey:
if event.is_action_pressed("ui_up"):
print("Phyiscs Frame ", Engine.get_physics_frames(), " Process Frame ", Engine.get_process_frames())
print("Emitting Signal \n")
InputDetected.emit()
func coroutine_await_physics():
print("Coroutine Start:")
print("Is action pressed? ", Input.is_action_pressed("ui_up"))
print("Is action just pressed? ", Input.is_action_just_pressed("ui_up"))
print("Phyiscs Frame ", Engine.get_physics_frames(), " Process Frame ", Engine.get_process_frames())
print("Awaiting.....")
print("Are we in physics frame? ", Engine.is_in_physics_frame(),"\n")
await InputDetected
print("After Signal:")
print("Is action pressed? ", Input.is_action_pressed("ui_up"))
print("Is action just pressed? ", Input.is_action_just_pressed("ui_up"))
print("Phyiscs Frame ", Engine.get_physics_frames(), " Process Frame ", Engine.get_process_frames())
print("Are we in physics frame? ", Engine.is_in_physics_frame(),"\n")
await get_tree().physics_frame
print("After await frame:")
print("Is action pressed? ", Input.is_action_pressed("ui_up"))
print("Is action just pressed? ", Input.is_action_just_pressed("ui_up"))
print("Phyiscs Frame ", Engine.get_physics_frames(), " Process Frame ", Engine.get_process_frames())
print("Are we in physics frame? ", Engine.is_in_physics_frame(),"\n")
await get_tree().physics_frame
print("After second await frame")
print("Is action pressed? ", Input.is_action_pressed("ui_up"))
print("Is action just pressed? ", Input.is_action_just_pressed("ui_up"))
print("Phyiscs Frame ", Engine.get_physics_frames(), " Process Frame ", Engine.get_process_frames())
print("Are we in physics frame? ", Engine.is_in_physics_frame(),"\n")
the terminal output:
InputEventKey: keycode=4194320 (Up), mods=none, physical=false, location=unspecified, pressed=true, echo=false
Phyiscs Frame 125 Process Frame 165
Emitting Signal
After Signal:
Is action pressed? true
Is action just pressed? true
Phyiscs Frame 125 Process Frame 165
Are we in physics frame? false
After await frame:
Is action pressed? true
Is action just pressed? true
Phyiscs Frame 126 Process Frame 165
Are we in physics frame? true
After second await frame
Is action pressed? true
Is action just pressed? false
Phyiscs Frame 127 Process Frame 167
Are we in physics frame? true
InputEventKey: keycode=4194320 (Up), mods=none, physical=false, location=unspecified, pressed=false, echo=false
I was going to open an issue but wanted to double check if this is actually an expected behavior?