MouseX BindAxis returning 0 unless mouse button depressed

Hi,

Unsure if this is a bug, or if (more likely) I am doing something wrong.

I have set up my axis mapping for the MouseX key value from the project settings.
50768-

I have also used the below code within my Character class SetupPlayerInputComponent() method.
InputComponent->BindAxis("MouseX", this, &AMyProjectCharacter::MouseX);

MouseX(float) simply prints the float to the console log for now.
Moving the mouse within my viewport prints a 0, unless any (left, right, middle) mouse button is depressed, at which point, the desired output is printed.

TL;DR:
MouseX axis binding returns a zero unless I click and drag.

I saw this issue on a prior [thread][2], however, it has been closed so am unsure if I am doing something wrong or have missed a simple bool in the settings somewhere.

Thanks,

Hi,

I have observed the same behavior on 4.8.2.

Did you manage to get this solved?
which is the proper way to handle this Axis Binding?

Thank you

Hey dandamann and JoMaz-

Could you post the code for the class called when the mouse is moved? I tried testing this in a first person template project and was able to see the values change without having to hold any buttons. In my Character.cpp I changed the InputComponent for “Turn” to call my own custom as such: InputComponent->BindAxis("Turn", this, &AMouseInputValuesTestCharacter::TestFunction);

I used the TestFunction to implement my turning as well as print the value to the log window and game screen.

void AMouseInputValuesTestCharacter::TestFunction(float Val)
{
	APawn::AddControllerYawInput(Val); //original function of Turn
	if (GEngine)
	{
		UE_LOG(LogTemp, Warning, TEXT("%f"), Val); //print to Log
		GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Cyan, FString::SanitizeFloat(Val)); //print to game screen
	}

}

Hey dandamann-

We’ve not heard from you in a few days and I will be marking this post as resolved for tracking purposes. If you are still having problems with the mouse axis feel free to add a comment to reopen the post and we will investigate further.

Cheers

Hey , I’m not one of the original posters, but seeing this problem in both release branch and promoted branch. Interesting pieces of info from testing.

  1. (No longer true, see bottom of post) I cannot seem to replicate the issue in the FPS sample project, though I have not tested adding new axis.

  2. Whatever the issue is, it’s propogated all the way from UPlayerInput::GetKeyValue(FKey InKey) forward. (KeyState->Value.X is always 0 unless a mouse button is down.)

My assumption here is that there’s some sort of additional config value that is missing somewhere from my project that is present in the FPS sample, but for the life of me I cannot find anything relevant, even after digging in a diff between the projects DefaultInput.ini files.

Continuing to dig for now. I’ve also been having issues getting this comment to post, so apologies if I come back later and find it’s posted 7x or something.

Edit: Further Digging - It seems like in FSceneViewport::ProcessAccumulatedPointerInput the NumMouseSamplesX/Y is always 0 as long as no buttons are being pressed. Further digging shows that in FSceneViewport::OnMouseMove, the calculated bool bViewportHasCapture is always false unless a mouse key is held down, resulting in the mouse not being sampled. Unfortunately the intricacies of how that boolean is calculated seem a little beyond a few minutes of digging, and I need to get groceries. More digging later.

Edit Round 2 : As per the below post:

This problem can be replicated in the base FPS Test application by simply pausing the game state and enabling the mouse cursor on the PlayerController actor.

1 Like

After a bit more digging, I found that enabling the mouse cursor in the player controller caused this problem (and thus, disabling fixed it.)

This problem can be replicated in the base FPS Test application by simply pausing the game state and enabling the mouse cursor on the PlayerController actor.

1 Like

Hey Lunaretic-

Could you post the setup you used to test this? To test on my end I created a code based First Person project and inside the Character.cpp file I wrote a function to test the MouseX value:

void AMouseTestCharacter::MyMouseFunction(float Val)
{
	APawn::AddControllerYawInput(Val);
	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Cyan, FString::SanitizeFloat(Val));
	}
}

Inside the SetupPlayerInputComponent() function I changed the line InputComponent->BindAxis("Turn", this, &APawn::AddControllerYawInput);
to call my function instead: InputComponent->BindAxis("Turn", this, &AMouseTestCharacter::MyMouseFunction);

This will make sure that I still turn in game by calling AddControlerYawInput() but will also print the value of the change in my MouseX. This works when moving the mouse without having to hold a button. If I then show mouse cursor inside blueprints, I do have to hold the mouse button to get my MouseX to report a value. This is because when the mouse is visible it is not locked to the game window and only interacting with the game when held.

Testing used stock FPS demo code, launched the game in the play in editor, confirmed no issues, paused game, selected the existing/active Player Controller and ticked on ‘Show Mouse Cursor’, then resumed and confirmed it was actively impossible to look around unless the mouse button was constantly held down.

Your comment > This is because when the mouse is visible it is not locked to the game window and only interacting with the game when held.

Makes it sound like this is an issue you are already aware of, though having the axis non-responsive unless a mouse button is held down if the cursor is visible/unlocked is a very strange behavior (and seemingly not documented anywhere public).

The behavior of the mouse with “ShowMouseCurcor” set has been reported (UE-20326) for investigation.

Cheers

sorry to resurrect such an old thread, but i had the same issue, because i was using SetInputModeGameAndUi. dont know if thats a bug or by design, but its kinda confusing. i was wondering why i stopped getting my MouseX/Y events all of a sudden, and why it still worked while holding the mouse button down.

1 Like

Adding a comment to this thread because I’ve had the same issue

If the mouse cursor is visible, even if you’re set to input mode Game Only and not UI or Game+UI, clicking in the viewport at all will deactivate the viewport as the current receiver of mouse events. From then on, your mouseX and mouseY values will be zero unless you click and hold a mouse button.

The code driving this is in SceneViewport.cpp and, if you want to disable this behaviour, the code to modifiy is:

		bReleaseMouseCapture =
			bCursorVisible ||
			ViewportClient->CaptureMouseOnClick() == EMouseCaptureMode::CaptureDuringMouseDown ||
			( ViewportClient->CaptureMouseOnClick() == EMouseCaptureMode::CaptureDuringRightMouseDown && InMouseEvent.GetEffectingButton() == EKeys::RightMouseButton );

I commented out the “bCursorVisible ||” part and it works as expected for me beyond this, but there’s likely a more nuanced fix (maybe a check for if you’re in UI mode) that supports all expected input modes.

1 Like

I am sorry, but, Is there a way to achieve this in blueprints at all? I am absolutely clueless how to implement this. xD

Nowadays, if all you need is the coordinates of the mouse, there is the node Get Mouse Position on any Player Controller blueprint to go around the issue.

This is a problem usually due to when you have the boolean Show Mouse Cursor marked true on the Player Controller’s Mouse Interface. No clue why.