Mouse Movement Using the Controller

**Hey Guys!
This should be a fairly straight forward venture, but for the life of me, I just can’t get it to work as it should.
Complex things are by far a LOT easier than the small things!

Anyhoo, I set up a simple input axis for the X and Y of the Right GamePad Stick called LookX/Y respectively.

I binded them like so:

InputComponent->BindAxis("LookY", this, &ACharacterLearningCharacter::LookY);
InputComponent->BindAxis("LookX", this, &ACharacterLearningCharacter::LookX);

Super simple!
Right stick = Mouse movement…

Then I set up the functions which work, but not correctly…
The comments explain whats going on:

void ASSCharacter::LookX(float Value)
    //Check for controller
    if (Controller != NULL)
        //Get the viewport from the player of the casted controller
        FViewport* v = CastChecked<ULocalPlayer>(Cast<APlayerController>(Controller)->Player)->ViewportClient->Viewport;    //This works

        //Check the pointer
        if (v != NULL)
            //Grab the current X value
            int tmpX = v->GetMouseX();                //This works
            //Update the value
            tmpX = tmpX + Value;                    //This works
            //Set the value
            v->SetMouse(tmpX, v->GetMouseY());        //This locks my mouse in position until I focus on the Viewport
            //AND, it doesn't update the position at all

            //Debug the value just to be sure
            if (GEngine != NULL) GEngine->AddOnScreenDebugMessage(-1, 0.001f, FColor::Green, FString::SanitizeFloat(Value));
            if (GEngine != NULL) GEngine->AddOnScreenDebugMessage(-1, 0.001f, FColor::Green, FString::FromInt(v->GetMouseY()));
            //THE DEBUG SHOWS THE VALUE BEING PASSED IN CORRECTLY, yet, the position won't change.


So yea, I don’t know why it’s not working.
When not focused on the viewport and the game is running, even if you move the mouse, it snaps back to the top left of the screen.
However once you manage to click the viewport, the mouse acts as normal, however it won’t be updated via my passed value.

Any ideas or any tips if anyone has encountered this before?

Thanks again guys!


What is the functionality you are trying to achieve? Manually setting the cursor position can be a tricky business!

**Hey JamesG!
What I’m trying to achieve is fairly simple:
Increment and decrement the X/Y values of the mouse position based on the right stick X/Y input values, which have been binded correctly.

It calls the function, does everything else ok, but won’t do anything correctly with the mouse positioning.


My binded actions/axis aren’t called when I have the system paused.
Even though the PlayerController and Pawn have “SetTickableWhenPaused(true);”
It was my understanding that ActorComponents such as UInputComponent will tick if their parent Actor ticks, so I don’t know what’s wrong.

However when I call “Cast<APlayerController>(Controller)->WasInputKeyJustPressed(EKeys::Escape)” in my Pawn Tick function, it works perfectly: paused or not.

Any ideas??



For the input bindings you need to mark it as bExecutesWhenPaused (or something like that I don’t have the code up in front of me).

In terms of updating the mouse position, that can be a tricky business. Because it is a hardware cursor, simply setting the position is often not enough because a mouse event needs to occur such that the system knows to update it. I think it is something that is on our list to fix, but I can’t recall for sure the status.

Hey Marc Audy!

I had actually just managed to get all of my action/axis binding working when paused!

I ended up doing something simple like this:

    //Run action bindings when paused
    for (int i = 0; i < InputComponent->GetNumActionBindings(); i++)
        InputComponent->GetActionBinding(i).bExecuteWhenPaused = true;

    //Run axis bindings when paused
    for (int i = 0; i < InputComponent->AxisBindings.Num(); i++)
        InputComponent->AxisBindings*.bExecuteWhenPaused = true;

And in terms of the mouse cursor being updating, it seems to work perfectly if the “PlayerController.bShowMouseCursor” is true,
although I’d like to be able to hide the mouse and retain the functionality.

Is there anyway to force a mouse event to cause updates that wouldn’t be obtrusive to the gameplay?

Thanks a bunch!!!


**Hey Guys!


I found a way around it all together.

I hold the “Mouse” FVector2D in the HUD class.
I update it via my character’s binded axis, which take in MouseX/Y and GamePad Right Stick X/Y.
And then for my mouse look controls for my character, I scripted a custom Deproject function for my HUD Mouse Position.

Thanks for all your help guys!

I’ll post the code if anyone wants it!