Disable LockMouseToViewport

I tried to SetInputMode(InputModeGameAndUI) (where InputModeGameAndUI is an FInputModeGameAndUI) in my ACustomPlayerController class, but with no success (the custom player controller does work, since it enables to show my mouse cursor).

I just want to disable bLockMouseToViewport, how should I do this (and where can I find the documentation for this)?

No it does not work. I have those two warnings (I am not sure they are related):

LogActor:Warning: GameSession /Game/UEDPIE_0_Untitled.Untitled:PersistentLevel.GameSession_4 has natively added scene component(s), but none of them were set as the actor's RootComponent - picking one arbitrarily

LogActor:Warning: GameNetworkManager /Game/UEDPIE_0_Untitled.Untitled:PersistentLevel.GameNetworkManager_4 has natively added scene component(s), but none of them were set as the actor's RootComponent - picking one arbitrarily

Thx!
Here is MyPlayerController.h:

UCLASS()
class BUILDER5_API AMyPlayerController : public APlayerController
{
	GENERATED_BODY()
	AMyPlayerController(const class FPostConstructInitializeProperties& PCIP);
	FInputModeGameAndUI InputMode;
};

Here is MyPlayerController.cpp:

AMyPlayerController::AMyPlayerController(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	bShowMouseCursor = true;
	CurrentMouseCursor = EMouseCursor::Default;
	UE_LOG(LogTemp, Warning, TEXT("AMyPlayerController %d"), int32(bShowMouseCursor));
	InputMode.SetHideCursorDuringCapture(false);
	InputMode.SetLockMouseToViewport(false);
	SetInputMode(InputMode);
}

It does log the warning:

LogTemp:Warning: AMyPlayerController 1

Thx! Well it does not work for me… I can log something in SetupInputComponent() so the function is called, but it seems to have no effect.

Just to make sure this is correct: I use my AMyPlayerController class by setting PlayerControllerClass = AMyPlayerController::StaticClass(); in my custom game mode class (which is selected in my world settings, and used), in the constructor.

Side question: how am I suppose to know that I should use functions like SetupInputComponent, by looking at the PlayerController class or is it documented somewhere? (How did you know?)

Thx! This is the most important part of MyPawn.cpp, the rest is to handle inputs and set the camera accordingly:

// In the constructor:
AutoPossessPlayer = EAutoReceiveInput::Player0;

	// Create a dummy root component we can attach things to.
	RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
	// Create a camera and a visible object
	// UCameraComponent* OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("OurCamera"));
	OurVisibleComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("OurVisibleComponent"));
	// Attach our camera and visible object to our root component. Offset and rotate the camera.
	//OurCamera->AttachTo(RootComponent);
	OurVisibleComponent->AttachTo(RootComponent);

	//Create our components
	RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
	OurCameraSpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraSpringArm"));
	OurCameraSpringArm->AttachTo(RootComponent);

	OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("GameCamera"));
	OurCamera->AttachTo(OurCameraSpringArm, USpringArmComponent::SocketName);

Is bAddDefaultMovementBindings a property of APawn?
I can’t find it here, nor Visual Studio (using UE4.8.3).

When I SetInputMode(InputMode); in the Tick event, the camera does not move anymore.

No, you are right, it is not locked! So it means my settings are overridden somewhere, maybe when I do AutoPossessPlayer = EAutoReceiveInput::Player0;?

When I click, the line 397 of SceneViewport.cpp:

 bool bShouldShowMouseCursor = World->GetFirstPlayerController()->ShouldShowMouseCursor()

causes a call to LockMouseToWidget() in Reply.h (which seems to disable the call to ReleaseMouseLock() performed by SetInputMode() )

I do have bindings to the input events in my AMyPawn class to control the pawn and camera moves (rotation and translation).

And if I SetInputMode in MyPlayerController::Tick the first 100 Ticks, and the stop setting input mode, my cursor is not locked for the first 100 ticks (and my camera does not work), and then it get locked (and my camera works).

Well I need to receive mouse input while pressing my mouse button (mouse button + dragging = camera rotation). I tried something which did not work. I am thinking of having a custom mouse cursor (a sprite) at cursor position instead. The only problem is to have a sprite always facing the camera, but I will watch this tutorial and see if it works.

It seems that the mouse is always locked within the viewport when an action button is clicked (no matter if AMyPlayerController::bShowMouseCursor == true and GEngine->GameViewport->Viewport->LockMouseToViewport(false)).

A workaround is to move the cursor at the opposite side of the screen when it reaches one side.

In MyPawn::Tick():

   // HasMouseMoved is a FIntPoint of MyPawn to keep track of the state of the cursor. 
   // If it just moved, we should not move it again at the opposite side 
   // (otherwise the position will blink between to opposite sides)

    FViewport* Viewport = GEngine->GameViewport->Viewport;
    FIntPoint Size = Viewport->GetSizeXY();

    UE_LOG(LogTemp, Warning, TEXT("Mouse pos: %d, %d"), Viewport->GetMouseX(), Viewport->GetMouseY());
    UE_LOG(LogTemp, Warning, TEXT("Size: %s"), *Size.ToString());
    const int32 MARGIN = 5;

    if(HasMouseMoved.X == 1 && Viewport->GetMouseX() > MARGIN || HasMouseMoved.X == -1 && Viewport->GetMouseX() < Size.X - MARGIN)
    {
        HasMouseMoved.X = 0;
    }
    if(HasMouseMoved.Y == 1 && Viewport->GetMouseY() > MARGIN || HasMouseMoved.Y == -1 && Viewport->GetMouseY() < Size.Y - MARGIN)
    {
        HasMouseMoved.Y = 0;
    }

    if(HasMouseMoved.X != 1 && Viewport->GetMouseX() <= MARGIN)
    {
        Viewport->SetMouse(Size.X-1, Viewport->GetMouseY());
        HasMouseMoved.X = -1;
    }
    else if(HasMouseMoved.X != -1 && Viewport->GetMouseX() >= Size.X-MARGIN)
    {
        Viewport->SetMouse(0, Viewport->GetMouseY());
        HasMouseMoved.X = 1;
    }

    if(HasMouseMoved.Y != 1 && Viewport->GetMouseY() <= MARGIN)
    {
        Viewport->SetMouse(Viewport->GetMouseX(), Size.Y-1);
        HasMouseMoved.Y = -1;
    }
    else if(HasMouseMoved.Y != -1 && Viewport->GetMouseY() >= Size.Y-MARGIN)
    {
        Viewport->SetMouse(Viewport->GetMouseX(), 0);
        HasMouseMoved.Y = 1;
    }