"Mouse XY 2D-Axis" supposedly gives a Vector but `BindVectorAxis` results in error

I set up the axis mapping in Project Settings/Input like so:

image

I then bind the “MouseMove” to a function in AMyPlayerController::BeginPlay():

void AMyPlayerController::BeginPlay()
{
	InputComponent->BindVectorAxis("MouseMove", this, &AMyPlayerController::MouseMove);
	Super::BeginPlay();
}

And I implement the Function AMyPlayerController::MouseMove(FVector Delta). However, UE complains:

Error: Ensure condition failed: AxisKey.IsAxis2D() || AxisKey.IsAxis3D()

Also, Delta is always (0, 0, 0).

What am I doing wrong?

Try using BindAxis, and do this bind in an overridden SetupPlayerInputComponent rather than on BeginPlay

1 Like

Repacing BindAxisVector with BindAxis results in a warning of Rider ““MouseMove” is not a name of any input axis”.

Moving from BeginPlay to SetupInputComponent results in UE crashing because of an access violation.

Not sure why Rider would complain there and not on your bind axis vector. I use VS so I can’t help much there.

Are you calling the super in your overridden function?

Super::SetupPlayerInputComponent(PlayerInputComponent);

Hard to know what’s going on without knowing what object it’s looking for when it throws the access violation. I’m still on 4.26 and some input stuff has changed in 5.0, but the way I’ve outlined is how I do mouse input bindings. You could make a fresh c++ third person project and look at how the character is setup for a clean example.

1 Like

Alright, thanks for your help so far. I moved the BindAxis to SetupInputComponent, where they belong.

It seems that I have to call Super::SetupInputComponent first, in order to avoid an access violation and a crash, like this:

void AMyPlayerController::SetupInputComponent()
{
	Super::SetupInputComponent();
	InputComponent->BindVectorAxis("MouseMove", this, &AMyPlayerController::MouseMove);
}

Maybe you can confirm that.

Moving from BindAxisVector to BindAxis gives me just a float parameter to work with, where I really want the “Mouse XY 2D-Axis” and that float parameter is always zero.

With BindAxis, you are binding per axis, so you need a MouseMoveUp, and MouseMoveRight. You should get a float for any input passed into that function. I’m not sure on the exact setup of bindvectoraxis as I don’t use it in my projects… It is made for things with a vector type input like pen tilt for instance.

Your input component setup looks correct, but I would setup 1D axis bindings for X and Y.

I thought about that, only then I have seperate events for one mouse movement. … which might be fine, as I can apply seperate rotations, but it seems there shoud be one MouseMove that gives me both axes.

Did you solve this issue? I’m trying to bind both rotations to the same function also. But i’m in the same boat, the axis vector is always zero.

No, I am using the tick function instead of the mouse move event now, where I get the mouse position.

my custom pawn
PlayerInputComponent->BindVectorAxis(EKeys::Mouse2D,this,&MyPawn::MyAction);
it work fun;

2 Likes