You can inherit a Blueprint Character from your Character C++ class:
.h file:
UCLASS()
class EXAMPLE_API AMyCharacter : public ACharacter
{
GENERATED_BODY()
protected:
virtual void BeginPlay() override;
public:
UFUNCTION(BlueprintImplementableEvent)
void OnWindowsLostFocus();
UFUNCTION(BlueprintImplementableEvent)
void OnWindowsGainFocus();
private:
void OnWindowFocusChanged(bool bIsFocused);
};
.cpp file:
void AMyCharacter::BeginPlay()
{
Super::BeginPlay();
FSlateApplication::Get().OnApplicationActivationStateChanged().AddUObject(this, &AMyCharacter::OnWindowFocusChanged);
}
void AMyCharacter::OnWindowFocusChanged(const bool bIsFocused)
{
if (bIsFocused)
{
OnWindowsGainFocus();
}
else
{
OnWindowsLostFocus();
}
}
And use: