Skip to content

Instantly share code, notes, and snippets.

@Anruin
Last active July 12, 2021 08:15
Show Gist options
  • Save Anruin/d327e2dbf98a0dc00803943787dacc65 to your computer and use it in GitHub Desktop.
Save Anruin/d327e2dbf98a0dc00803943787dacc65 to your computer and use it in GitHub Desktop.
UE4 UMG Debounce Macro
// Can be used on buttons to allow single click in some period of time, for example limit to few clicks per second.
#define DEBOUNCE(s, ...) \
static bool bActive; \
if (!bActive) { \
bActive = true; \
__VA_ARGS__; \
FTimerHandle DebounceTimerHandle; \
GetWorld()->GetTimerManager().SetTimer(DebounceTimerHandle, FTimerDelegate().CreateLambda([](){\
bActive = false; \
}), s, false); \
}
// Usage examples:
DEBOUNCE(ClickDebounceTime, OnButtonClicked.Broadcast());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment