RealDocs

UGameplayStatics::SetViewportMouseCaptureMode

function Engine Blueprint Since 4.0
#include "Kismet/GameplayStatics.h"
Access: public Specifiers: staticUFUNCTIONBlueprintCallable

Description

Sets how the game viewport captures the mouse cursor. Use this to override the project-default capture mode at runtime, for example when switching between game and menu states.

Caveats & Gotchas

  • Changing capture mode does not automatically show or hide the OS cursor — call APlayerController::SetShowMouseCursor in addition if you need cursor visibility to change.
  • This is a global viewport setting; it applies to all local players simultaneously. Per-player cursor handling should be done through the PlayerController input mode API instead.

Signature

static ENGINE_API void SetViewportMouseCaptureMode(const UObject* WorldContextObject, const EMouseCaptureMode MouseCaptureMode);

Parameters

Name Type Description Default
WorldContextObject const UObject* Object used to retrieve the world context.
MouseCaptureMode const EMouseCaptureMode The desired capture mode for the viewport mouse.

Return Type

void

Example

Release mouse on pause C++
// When opening the pause menu, release the cursor
UGameplayStatics::SetViewportMouseCaptureMode(this, EMouseCaptureMode::NoCapture);

// When closing the menu, re-capture
UGameplayStatics::SetViewportMouseCaptureMode(this, EMouseCaptureMode::CapturePermanently);

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.