Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

MouseX BindAxis returning 0 unless mouse button depressed.


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.
alt text

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.

MouseX axis binding returns a zero unless I click and drag.

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


Product Version: UE 4.8
more ▼

asked Jul 20 '15 at 06:55 AM in C++ Programming

avatar image

11 1 1 2

avatar image JoMaz Aug 11 '15 at 11:45 PM


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

avatar image Doug E ♦♦ STAFF Aug 12 '15 at 04:21 PM

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
avatar image Lunaretic Aug 21 '15 at 06:05 AM

Hey Doug, 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.

avatar image Lunaretic Aug 21 '15 at 07:21 AM

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.

avatar image Doug E ♦♦ STAFF Aug 21 '15 at 01:57 PM

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)
     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.

avatar image Lunaretic Aug 21 '15 at 04:45 PM

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).

avatar image Doug E ♦♦ STAFF Aug 26 '15 at 08:54 PM

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


Doug Wilson

avatar image nco2k Jul 04 '18 at 01:46 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.


Doug Wilson

more ▼

answered Aug 18 '15 at 06:09 PM

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question