Hello,
I have a setup like this to handle my UI interactions in the game. A Parent Widget that holds references to child widgets which switches between these child widgets when user input something/ events occur in game.
In order for parent widget to do the switching I’m broadcasting events from child view to parent view which listens to these events and do the necessary actions.
So in order to handle Pause and Unpause of the game I added this key input listener in my PlayerController
FInputActionBinding& PauseBinding = InputComponent->BindAction("Pause", IE_Pressed, this, &AWaveGamePlayerController::BroadcastEscape);
PauseBinding.bConsumeInput = true;
PauseBinding.bExecuteWhenPaused = true;
And when this Input action is triggered the below will happen. Its a multicast delegate that I’m firing from the player controller at this moment.
OnPressEscape.Broadcast();
And the Parent Widget who listen to this event does the following.
bool isGamePaused = CurrentPlayerController->IsPaused();
if (isGamePaused)
{
bool _SuccessUnPausing = CurrentPlayerController->SetPause(false);
if (_SuccessUnPausing)
{
// update states of the UI
// show/ switch to appropriate in game HUD widget
// enable inputs to Game only
FInputModeGameOnly InputModeData;
CurrentPlayerController->SetInputMode(InputModeData);
CurrentPlayerController->bShowMouseCursor = false;
}
else
{
UE_LOG(LogTemp, Warning, TEXT("FAILED TO UNPAUSE"));
}
}
else
{
bool _SuccessPausing = CurrentPlayerController->SetPause(true);
if (_SuccessPausing)
{
// update states of the UI
// show/ switch to appropriate widget
// enable inputs to UI only
FInputModeUIOnly InputModeData;
InputModeData.SetWidgetToFocus(this->TakeWidget());
InputModeData.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock);
/* Set input mode */
CurrentPlayerController->SetInputMode(InputModeData);
CurrentPlayerController->bShowMouseCursor = true;
}
else
{
UE_LOG(LogTemp, Warning, TEXT("FAILED TO PAUSE"));
}
}
Problem here is that when the InputMode
is set to UI only the Input action event wont trigger on key press. But if I dont set InputMode
to UI only it works fine. It kinda makes sense since I set my InputMode to UI only. But I want to be able to trigger the Pause
input action again to Unpause the game.
Anything that Im doing wrong here or something I should try differently ? Thank in advance.