Add a way to debounce signal handler #11267
Replies: 4 comments 3 replies
-
I made this: func debounced(fn: Callable, debounce_sec: float) -> Callable:
# is array because they are passed by reference
# (it's hacky, I know)
var last_call_usec: PackedInt64Array = [-1.0]
return func():
if last_call_usec[0] == -1.0 or (Time.get_ticks_usec() - last_call_usec[0]) * 1e-6 > debounce_sec:
last_call_usec[0] = Time.get_ticks_usec()
fn.call() It's kind of goofy but it seems to work |
Beta Was this translation helpful? Give feedback.
-
This could also be provided for throttling, but debouncing is arguably needed more often in UI interactions. |
Beta Was this translation helpful? Give feedback.
-
@dalexeev What do you think? I think you're one of the most knowledgeable person I know about |
Beta Was this translation helpful? Give feedback.
-
If godot provides signal debouncing/throttling on the engine level shouldn't it be done in a way that's compatible with persisting connections so that it can be serialized and edited through the editor UI, just like one-shot and deferred? |
Beta Was this translation helpful? Give feedback.
-
Inspired by godotengine/godot#99812, I believe debouncing is a common requirement for controls that accept user input.
We can provide a special
Callable
that calls the wrapped childCallable
in a debounced manner.I am not familiar with the implementation of
Callable
. How to obtain the time may require further design.Beta Was this translation helpful? Give feedback.
All reactions