How to save and restore any value with RAII approach in Unreal Engine
Imagine you’re in a situation where you need to save and restore a value. For instance, let’s say you have a UMG widget that you want to hide temporarily, do some stuff, and then bring back its previous visibility state, all within a single function. The most straightforward approach might be to store the value in a temporary variable, modify it, and then revert it back, like this: ESlateVisibility VisibilityState; const ESlateVisibility PreviousVisibility = VisibilityState; VisibilityState = ESlateVisibility::Hidden; // Do smth....