Last active
July 12, 2021 08:15
-
-
Save Anruin/d327e2dbf98a0dc00803943787dacc65 to your computer and use it in GitHub Desktop.
UE4 UMG Debounce Macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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