Class GameDev* SheepAdult

[Unreal Engine] Game Pause 시 특정 키 입력 가능하게 하기 본문

Unreal Engine

[Unreal Engine] Game Pause 시 특정 키 입력 가능하게 하기

SheepAdult 2022. 7. 12. 20:11

 메뉴를 열거나 pause 키로 게임을 중단시키고 싶을 경우 일반적으로 

UGameplayStatics::SetGamePaused(GetWorld(), true);

를 사용해 게임을 중단시킨다. 그리고 다시 게임으로 돌아오기 위해 ESC를 누르거나 P키(일반적으로 Pause키)를 누르면 안 눌러지는 것을 알 수 있다. 왜냐하면 게임이 중단되면 Input도 중단되기 때문이다. 그러면 FlipFlop형태로 중단했다가 재개하려면 어떻게 해야 할까?

 

 블루프린트를 살펴보면 아래와 같은 bool 값이 있다.

키보드 P의 이벤트

저기 Execute when Paused가 있는 것을 알 수 있는데 저것을 true로 바꿔주면 된다. c++ 에선 아래와 같다.

void AMainCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);
	check(PlayerInputComponent);

	PlayerInputComponent->BindAction("ESCMenu", IE_Pressed, this, &AMainCharacter::ESCMenu).bExecuteWhenPaused = true;
}

입력 키를 함수와 바인드 시켜줄 때 작성해 주면 된다.