GameGetsMouseControl

GameGetsMouseControl

#Overview

name: GameGetsMouseControl

The value of this variable can be defined or overridden in .ini config files. 1 .ini config file referencing this setting variable.

It is referenced in 6 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of GameGetsMouseControl is to determine whether the game should automatically receive mouse control when Play-in-Editor (PIE) starts in Unreal Engine 5.

This setting variable is primarily used in the Play-in-Editor system, which is part of the Unreal Editor’s gameplay testing and debugging functionality. It is referenced in various modules including LevelEditor, UnrealEd, and MovieSceneCaptureDialog.

The value of this variable is typically set in the ULevelEditorPlaySettings class, which is a configuration class for Play-in-Editor settings. It can be modified through the project settings in the Unreal Editor.

GameGetsMouseControl interacts with other variables and systems, particularly those related to input handling and viewport focus. For example, it’s used in conjunction with variables like ViewportGetsHMDControl for VR-related settings.

Developers should be aware that:

  1. This setting doesn’t affect VR mode, which always takes focus.
  2. When set to false, the game requires a click in the viewport to gain mouse control.
  3. It can impact the behavior of other input-related settings and functions.

Best practices when using this variable include:

  1. Consider the target audience and gameplay style when deciding whether to enable automatic mouse control.
  2. Be consistent with its usage across different play modes (PIE, Standalone, etc.) to ensure a uniform testing experience.
  3. Remember to reset this setting if temporarily changing it for specific testing scenarios.
  4. When developing for both desktop and VR platforms, be aware of how this setting interacts with VR-specific controls.

#Setting Variables

#References In INI files

Location: <Workspace>/Projects/Lyra/Config/DefaultEditorPerProjectUserSettings.ini:5, section: [/Script/UnrealEd.LevelEditorPlaySettings]

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Plugins/Tests/CQTest/Source/CQTest/Private/Components/PIENetworkComponent.cpp:105

Scope (from outer to inner):

file
function     void FBasePIENetworkComponent::StartPie

Source code excerpt:

	}
	PlaySettings->bLaunchSeparateServer = ServerState->bIsDedicatedServer;
	PlaySettings->GameGetsMouseControl = false;
	PlaySettings->SetRunUnderOneProcess(true);

	FLevelEditorModule& LevelEditorModule = FModuleManager::Get().GetModuleChecked<FLevelEditorModule>(TEXT("LevelEditor"));

	FRequestPlaySessionParams SessionParams;
	SessionParams.WorldType = EPlaySessionWorldType::PlayInEditor;

#Loc: <Workspace>/Engine/Source/Editor/LevelEditor/Private/SLevelViewport.cpp:4121

Scope (from outer to inner):

file
function     void SLevelViewport::StartPlayInEditorSession

Source code excerpt:


	// Whether to start with the game taking mouse control or leaving it shown in the editor
	ActiveViewport->SetPlayInEditorGetsMouseControl(GetDefault<ULevelEditorPlaySettings>()->GameGetsMouseControl);
	ActiveViewport->SetPlayInEditorIsSimulate(bInSimulateInEditor);
	
	ActiveViewport->OnPlayWorldViewportSwapped( *InactiveViewport );
	
	LevelViewportClient->AddRealtimeOverride(false, LOCTEXT("LevelViewport_RealTimeDisableOnPie", "Disable LevelViewport Realtime for PIE"));

#Loc: <Workspace>/Engine/Source/Editor/MovieSceneCaptureDialog/Private/MovieSceneCaptureDialogModule.cpp:485

Scope (from outer to inner):

file
function     void FInEditorCapture::OverridePlaySettings

Source code excerpt:


	// Reset everything else
	PlayInEditorSettings->GameGetsMouseControl = false;
	PlayInEditorSettings->ShowMouseControlLabel = false;
	PlayInEditorSettings->ViewportGetsHMDControl = false;
	PlayInEditorSettings->ShouldMinimizeEditorOnVRPIE = true;
	PlayInEditorSettings->EnableGameSound = CaptureObject->AudioCaptureProtocolType != UNullAudioCaptureProtocol::StaticClass();
	PlayInEditorSettings->bOnlyLoadVisibleLevelsInPIE = false;
	PlayInEditorSettings->bPreferToStreamLevelsInPIE = false;

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Classes/Settings/LevelEditorPlaySettings.h:225

Scope (from outer to inner):

file
class        class ULevelEditorPlaySettings : public UObject

Source code excerpt:

	/** Should Play-in-Editor automatically give mouse control to the game on PIE start (default = false). Note that this does not affect VR, which will always take focus */
	UPROPERTY(config, EditAnywhere, Category=PlayInEditor, meta=(ToolTip="Give the game mouse control when PIE starts or require a click in the viewport first"))
	bool GameGetsMouseControl;

	/** While using the game viewport, it sends mouse movement and clicks as touch events, instead of as mouse events. */
	UPROPERTY(config, EditAnywhere, Category=PlayInEditor)
	bool UseMouseForTouch;

	/** Whether to show a label for mouse control gestures in the PIE view. */

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/PlayLevel.cpp:1682

Scope (from outer to inner):

file
function     void UEditorEngine::GiveFocusToLastClientPIEViewport

Source code excerpt:

		const bool bPreviewTypeIsVR = PlayInEditorSessionInfo->OriginalRequestParams.SessionPreviewTypeOverride.Get(EPlaySessionPreviewType::NoPreview) == EPlaySessionPreviewType::VRPreview;
		const bool bIsVR = IVREditorModule::Get().IsVREditorEnabled() || (bPreviewTypeIsVR && GEngine->XRSystem.IsValid());
		const bool bGameGetsMouseControl = PlayInEditorSessionInfo->OriginalRequestParams.EditorPlaySettings->GameGetsMouseControl;

		if (PlayInEditorSessionInfo->OriginalRequestParams.WorldType == EPlaySessionWorldType::PlayInEditor && (bGameGetsMouseControl || bIsVR))
		{
			FSlateApplication::Get().SetAllUserFocusToGameViewport();
		}
	}

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/PlayLevel.cpp:3433

Scope (from outer to inner):

file
function     TSharedRef<SPIEViewport> UEditorEngine::GeneratePIEViewportWindow

Source code excerpt:

	GameLayerManagerRef->SetSceneViewport(InSlateInfo.SlatePlayInEditorWindowViewport.Get());

	const bool bShouldGameGetMouseControl = InSessionParams.EditorPlaySettings->GameGetsMouseControl || (bEnableStereoRendering && GEngine && GEngine->XRSystem.IsValid());
	InSlateInfo.SlatePlayInEditorWindowViewport->SetPlayInEditorGetsMouseControl(bShouldGameGetMouseControl);
	PieViewportWidget->SetViewportInterface(InSlateInfo.SlatePlayInEditorWindowViewport.ToSharedRef());

	FSlateApplication::Get().RegisterViewport(PieViewportWidget);

	InSlateInfo.SlatePlayInEditorWindow = PieWindow;