タイトル: 「Set Game Paused」の使い方と詳細解説
SEOタイトル: Unreal Engine Set Game Paused 完全ガイド(GameMode / TimeDilation / 入力モード)
| この記事の要点 |
|
Set Game Paused ノードの基本
Unreal Engine の Set Game Paused ノードは、ゲームをワンクリックで一時停止する公式 API です。Blueprint の任意の場所から呼び出せ、引数は Paused (bool) のみ。Pause メニューを開く際の鉄板コードです。
[Blueprint Node]
Set Game Paused
Paused: true → ゲーム停止
Paused: false → ゲーム再開
戻り値: 成功した場合 true
C++ での呼び方
#include "Kismet/GameplayStatics.h"
// 停止
UGameplayStatics::SetGamePaused(GetWorld(), true);
// 再開
UGameplayStatics::SetGamePaused(GetWorld(), false);
// 現在の状態を取得
bool bPaused = UGameplayStatics::IsGamePaused(GetWorld());
停止中に止まる物 / 止まらない物
Set Game Paused が true のとき、何が止まり何が動き続けるかを理解しておくのが重要です:
| 項目 | 状態 | 備考 |
|---|---|---|
| Actor の Tick | 止まる | 既定動作 |
| Component の Tick | 止まる | 既定動作 |
| Physics Simulation | 止まる | Rigid Body 更新も停止 |
| Animation | 止まる | Anim BP の Tick が止まる |
| Particle System (Cascade) | 止まる | |
| Niagara System | 止まる | |
| Sound | 続く | BGM はそのまま流れる |
| UMG Widget の Tick | 続く | UI は動き続けるので Pause メニューが操作可能 |
| Player Controller | 続く | 入力受付のため |
| Set Timer by Function Name | 止まる | 世界時間に従う |
| Real Time Timer | 続く | Real Time フラグ ON のもの |
Pause 中にも動かしたい Actor を作る
Pause 中にも特定の Actor だけ動かしたい場合 (Pause 中の演出用エフェクト、UI 連動カメラ等):
// AActor の Tick を Pause 中も実行
AMyActor::AMyActor()
{
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bTickEvenWhenPaused = true; // ★
SetTickableWhenPaused(true); // C++ 補助
}
// UActorComponent の場合
PrimaryComponentTick.bTickEvenWhenPaused = true;
Blueprint の場合は Class Defaults > Tick > Tick Even When Paused にチェック。
典型的な Pause メニュー実装
[Player Controller Blueprint]
Input Action: PauseGame (Esc キー想定)
1. Branch: Is Game Paused?
true → Set Game Paused (false)
Remove Widget
Set Input Mode Game Only
Set Show Mouse Cursor (false)
false → Create Widget (PauseMenuWidget)
Add to Viewport
Set Game Paused (true)
Set Input Mode UI Only (target widget)
Set Show Mouse Cursor (true)
C++ 版
void AMyPlayerController::TogglePause()
{
bool bIsPaused = UGameplayStatics::IsGamePaused(this);
if (bIsPaused)
{
// 再開
UGameplayStatics::SetGamePaused(this, false);
if (PauseMenuWidget) PauseMenuWidget->RemoveFromParent();
FInputModeGameOnly InputMode;
SetInputMode(InputMode);
bShowMouseCursor = false;
}
else
{
// 停止
if (!PauseMenuWidget)
{
PauseMenuWidget = CreateWidget(this, PauseMenuClass);
}
PauseMenuWidget->AddToViewport();
UGameplayStatics::SetGamePaused(this, true);
FInputModeUIOnly InputMode;
InputMode.SetWidgetToFocus(PauseMenuWidget->TakeWidget());
SetInputMode(InputMode);
bShowMouseCursor = true;
}
}
Set Game Paused vs Time Dilation
ゲームを完全停止するかスローにするかで使い分けます:
| Set Game Paused | Set Global Time Dilation | |
|---|---|---|
| 動作 | 完全停止 | 時間流速を変更 |
| Tick | 呼ばれない | DeltaTime が縮む |
| UI 操作 | ○(UMG 別系統) | ○ |
| 用途 | Pause メニュー | バレットタイム / スローモーション |
// スローモーション (0.3 倍速)
UGameplayStatics::SetGlobalTimeDilation(GetWorld(), 0.3f);
// 等速
UGameplayStatics::SetGlobalTimeDilation(GetWorld(), 1.0f);
// 個別 Actor だけスロー (他はそのまま)
MyActor->CustomTimeDilation = 0.3f;
Pause 中の入力モード
| 入力モード | 用途 |
|---|---|
| Game Only | 通常プレイ。マウスはキャプチャ |
| UI Only | UI のみ受付。プレイヤー操作不可(Pause メニューに最適) |
| Game and UI | 両方受付。インベントリ等で使用 |
マルチプレイヤーでの Pause
マルチプレイ環境では Set Game Paused が効かないのがデフォルトです。理由は他プレイヤーまで停止させると不公平になるため。サーバ側で AGameModeBase::SetPause(PlayerController) を実装する必要があります:
// GameMode で許可
AMyGameMode::AMyGameMode()
{
bPauseable = true; // 既定 true だが、Networked Game では false にする方が安全
}
// 全プレイヤー停止には GameMode::SetPause で判定
bool AMyGameMode::AllowPausing(APlayerController* PC)
{
return false; // マルチプレイで一切停止を許さない
}
FAQ
Q: Pause メニューが効かない (キー押しても反応しない)
A: ① 入力モードが UI Only になっていない、② InputAction の Bind 先が間違っている、③ Player Controller がない (Pawn から直接 Bind してしまっている) を確認。
Q: Pause 中に BGM も止めたい
A: UAudioComponent の bIsUISound を false にし、SoundClass で個別に音量を下げるか、Audio Volume の Mixer Snapshot で BGM だけミュート。
Q: Pause 中のタイマーが進む
A: SetTimerForNextTick や Tickable Object など Real Time 駆動の物は止まりません。FTimerHandle + GetWorldTimerManager() なら停止対象。
Q: Networked Multiplayer で Set Game Paused が動かない
A: 仕様です。シングルプレイか、AllowPausing で個別判断するか、UI Only モードで擬似 Pause を実装してください。