Mouse cursor does not function in Standalone version as it does in PIE

4.14.1

Functionality:

  • Right Click drag looks around (.2 sec
    to initiate hold)
  • Record the mouse position at the time of held click to place the cursor back at the same position once RMB up event fires.
  • Right click still available
  • Left click available
  • WASD keys move character as normal

In PIE this works fine as expected.
In Standalone, the mouse cursor never stays in the game windows. It acts sporadic and unpredictably in the upper left hand of the monitor the game window is in. I have to close the window in the Windows task bar.

Windows 10 Pro Version 1607, OS Build 14393.447, 64 bit, 64g RAM, i7-5820 CPU @ 3.3GHz

3 Monitors on a GeForce GTX 970, 4g memory

  1. Launch 4.14.1 from the Epic Launcher
  2. Create new C++ Third Person Example, Desktop/Console, Max Quality, no starter content
  3. Create new BLUEPRINT in the ThirdPersonCPP/Blueprints folder, inherit from GameModeBase, called “MyGameModeBase”
  4. Create new C++ class, Inherit from PlayerController, called “MyPlayerController”.
  5. Go into ThirdPersonCPP/Blueprints folder, open up “MyGameModeBase” blueprint and change Player Controller Class to “MyPlayerController”.
  6. In the blueprint “MyGameModeBase”, change Default Pawn Class to “ThirdPersonCharacter”
  7. Go into Project Settings, change Default GameMode to “MyGameModeBase”
  8. Go into Project Settings, Input, add Action mapping “RightMouseButton”, assign to Right Mouse Button
  9. Go into Project Settings, Input, add Action mapping “LeftMouseButton”, assign to Left Mouse Button
  10. Delete the ThirdPersonCharacter placed on the mapping
  11. Drag in a PlayerStart from the Modes tab
  12. Go into the Projects “.h” file, change “#include EngineMinimal.h” to “Engine.h”

MyPlayerController.h
*/

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "GameFramework/PlayerController.h"
#include "GameFramework/Character.h"
#include "MyPlayerController.generated.h"

USTRUCT()
struct FMouseCursor
{
	GENERATED_BODY()

	UPROPERTY()
	float X;

	UPROPERTY()
		float Y;
};

/**
 * 
 */
UCLASS()
class TESTINGMOUSE_API AMyPlayerController : public APlayerController
{
	GENERATED_BODY()
	
	AMyPlayerController(const FObjectInitializer& ObjectInitializer);

	virtual void BeginPlay() override;
	
public:
	virtual void SetupInputComponent();

	/* Handle to manage the timer for Right Mouse Button held*/
	FTimerHandle RMBTimerHandle;

protected:
	void AddYawInputCustom(float Val);
	void AddPitchInputCustom(float val);

	void OnRightMouseDown();
	void OnRightMouseUp();
	void OnLeftMouseDown();
	void OnLeftMouseUp();

private:
	void OnRightMouseButtonHeldDown();

	float RightMouseButtonHoldInterval;

	bool bIsRightMouseButtonHeld;
	bool bIsLeftMouseButton;

	FMouseCursor LastMouseCursor;


};


MyPlayerController.cpp
// Fill out your copyright notice in the Description page of Project Settings.

#include "TestingMouse.h"
#include "MyPlayerController.h"

AMyPlayerController::AMyPlayerController(const class FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	bShowMouseCursor = true;
	bIsRightMouseButtonHeld = false;
	bIsLeftMouseButton = false;

	RightMouseButtonHoldInterval = 0.2f;

}

void AMyPlayerController::BeginPlay()
{
	Super::BeginPlay();

	/* This is to allow input even when the cursor is at the edge of the screen*/
	//FInputModeGameOnly GameMode;
	FInputModeGameAndUI GameModeUI;
	this->SetInputMode(GameModeUI);
}

void AMyPlayerController::SetupInputComponent()
{
	Super::SetupInputComponent();

	InputComponent->BindAxis("Turn", this, &AMyPlayerController::AddYawInputCustom);
	InputComponent->BindAxis("LookUp", this, &AMyPlayerController::AddPitchInputCustom);

	InputComponent->BindAction("RightMouseButton", IE_Pressed, this, &AMyPlayerController::OnRightMouseDown);
	InputComponent->BindAction("RightMouseButton", IE_Released, this, &AMyPlayerController::OnRightMouseUp);

	InputComponent->BindAction("LeftMouseButton", IE_Pressed, this, &AMyPlayerController::OnLeftMouseDown);
	InputComponent->BindAction("LeftMouseButton", IE_Released, this, &AMyPlayerController::OnLeftMouseUp);

}

void AMyPlayerController::OnRightMouseDown()
{
	UE_LOG(LogTemp, Warning, TEXT("right button DOWN"));

	GetMousePosition(LastMouseCursor.X, LastMouseCursor.Y);
	//GetWorld()->GetTimerManager().SetTimer(RMBTimerHandle, this, &AAWPlayerController::OnRightMouseButtonHeldDown, RightMouseButtonHoldInterval, false);
	GetWorldTimerManager().SetTimer(RMBTimerHandle, this, &AMyPlayerController::OnRightMouseButtonHeldDown, RightMouseButtonHoldInterval, false);

	UE_LOG(LogTemp, Warning, TEXT("right button DOWN EXIT"));
	//bIsRightMouseButtonHeld = true;
}

void AMyPlayerController::OnRightMouseButtonHeldDown()
{
	if (!bIsRightMouseButtonHeld)
	{
		GetMousePosition(LastMouseCursor.X, LastMouseCursor.Y);
	}

	bIsRightMouseButtonHeld = true;

	UE_LOG(LogTemp, Warning, TEXT("HELD right button DOWN"));

}

void AMyPlayerController::OnRightMouseUp()
{
	// Ensure the RMB timer is cleared
	GetWorldTimerManager().ClearTimer(RMBTimerHandle);

	if (bIsRightMouseButtonHeld)
	{
		FViewport* myviewport = CastChecked<ULocalPlayer>(this->Player)->ViewportClient->Viewport;
		myviewport->SetMouse(LastMouseCursor.X, LastMouseCursor.Y);
	}
	else
	{
	}

	bIsRightMouseButtonHeld = false;
	UE_LOG(LogTemp, Warning, TEXT("right button UP"));


	bShowMouseCursor = true;
}

void AMyPlayerController::OnLeftMouseDown()
{
	UE_LOG(LogTemp, Warning, TEXT("LEFT button down"));

	bIsLeftMouseButton = true;
}

void AMyPlayerController::OnLeftMouseUp()
{
	UE_LOG(LogTemp, Warning, TEXT("LEFT button up"));
	bIsLeftMouseButton = false;
}

void AMyPlayerController::AddYawInputCustom(float Val)
{

	if (bIsRightMouseButtonHeld)
	{
		//Release the mouse events and don't draw the mouse
		bShowMouseCursor = false;

		if (Val != 0.f && this->IsLocalPlayerController())
		{
			AddYawInput(Val);
		}
	}
}

void AMyPlayerController::AddPitchInputCustom(float Val)
{
	if (bIsRightMouseButtonHeld)
	{
		bShowMouseCursor = false;
		if (Val != 0.f && this->IsLocalPlayerController())
		{
			AddPitchInput(Val);
		}
	}
}

The cursor will not leave the upper left whenever I try to move it to the game window. I can move the cursor around it, but as soon as it touches it, it jumps to the left corner and acts like a rabbit on speed.

Am I wrong to post this as bug? Am I doing something incorrectly?

Partial source

Here is the C++ code, the sln and the .uproject.

The GetMousePosition is returning zeroes. I removed the code that sets the mouse position, but the problem continues.

It still works in the Editor which once again shows me that when something works, I need to confirm if the code is working the way I think it is working. Because the mouse stays in the position when I right click and spin it around.

Hello,

Are you using any third-party plugins in your project? After trying to compile, I received an error stating that it had dependencies on a MORT plugin. I’d recommend removing that plugin from the project and seeing if the same behavior still occurs.

I already have as mentioned in the other thread.

The problem persists without the plugin.

After creating a clean project to follow your repro in, I was unable to reproduce the same behavior. In my standalone, the mouse functioned exactly as it does in PIE.

I’d recommend trying to unhook your third monitor to see if it could be something related to this, as we’ve seen problems like that in the past.

Let me know if that makes a difference.

I took the 3rd monitor out. Rebooted. Same issue.
Took the 2nd monitor out. Rebooted. Same issue.

My two main monitors are Dell U3415W.
My third is HP Envy 27 IPS.

I then hooked up the HP Envy only. Problem does NOT manifest.

So the problem is when I use my Dell monitor.

Also works fine only on the HP Envy when I make it my main display without having to unhook everything.

It’s possible that there is an issue with the resolution of the affected monitors if they aren’t all the same.

Could you please reconnect everything and provide your dxdiag so we can see the specs of all of the monitors?

dxdiag

Here ya go. I can replicate it working correctly with all monitors connected but the HP Envy being marked as the main display in Win 10. When one of the Dell monitors is the main display, the problem shows.

When you have one of the Dell monitors set as the main display, are you running 3440 x 1440?

Yes, I am!

Hey acxsasx,

Apologies for the delay. I need to get access to some hardware to test this and I’ll respond as soon as I have new information.

It’s all good! Fortunately this does not impact what I am doing now.

This problem does not appear in my builds for client and dedicated server. On the client portion, built from source, the mouse works just fine on the 3440x1440.

Since you have the setup handy, could you do me a favor and see if the same issue occurs in a packaged game? It’s possible that it’s just specific to standalone at a certain resolution.

Great, that’s good to know that it’s limited to Standalone.

One more thing, could you try changing the resolution of the Standalone game window in your Edit->Editor Preferences->Play section to match your monitor’s resolution?

I have a feeling this might make a difference, so it’s worth a shot.

I took the clean project (now in 4.14.3) and packaged it. (File->Package Project->Windows->Windows(64bit).

All works fine.

Tried it again in PIE with the Stand Alone option and the problem shows up.