Single-fire reliable events #189
-
Right now, However, for single-process-frame events like I need the event to be triggered only once right after the frame that it was called in, but I can't find any solutions at the moment. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
This is caused by the custom tick loop. From the Input docs:
What happens is between pressing the button, a frame might pass before the tick loop runs next. Imagine a timeline like this:
You can move your input to a separate variable on your class, gather input on every frame, use the gathered input in the first tick in the loop, then reset the input. Something like this: var is_jumping: bool = false
func _ready():
NetworkTime.after_tick.connect(_reset)
func _process():
if Input.is_action_just_pressed("jump"):
is_jumping = true
func _reset(_delta, _tick):
is_jumping = false This way, if the input is pressed between two ticks, it will be remembered. After the first tick in the loop, the input is reset back to false. I'm mentioning the tick loop, because in some cases the tick loop needs to run multiple ticks to catch up. So in this case, even if the input was pressed, it will be used only in the first tick of the loop. Resetting only after the tick loop can also be useful for continuous inputs like movement. Let me know if this clears it up! |
Beta Was this translation helpful? Give feedback.
-
For anyone who's trying to do this same thing in the future, I'm not exactly sure why, but make sure to clear input in |
Beta Was this translation helpful? Give feedback.
This is caused by the custom tick loop. From the Input docs:
What happens is between pressing the button, a frame might pass before the tick loop runs next. Imagine a timeline like this:
You can move your input to a separate variable on your class, gather input on every frame, use the gathered input in the first tick in the loop, then reset the input. Something like this: