How to Capture Mouse Movement

In my combat system, I want to determine the direction in which the character should attack by the movement of the mouse after the player clicks the melee button. I have the framework for this setup, but I cannot get the mouse location properly. Currently, I have two fvector2ds, the center of screen and mouse location. To calculate the center of the screen, I have the following:

FIntPoint ViewportSize;
UGameplayStatics::GetPlayerController(this, 0)->GetViewportSize(ViewportSize.X, ViewportSize.Y);
UE_LOG(LogTemp, Warning, TEXT(“Viewport Size: (%f, %f)”), ViewportSize.X, ViewportSize.Y);
CenterOfScreen = FVector2D(ViewportSize.X, ViewportSize.Y);

To calculate the mouse:

if (PlayerController)
{
	//PlayerController->GetInputMouseDelta(DeltaMouseLoc.X, DeltaMouseLoc.Y);
	PlayerController->GetMousePosition(DeltaMouseLoc.X, DeltaMouseLoc.Y);
}
MouseLocation = DeltaMouseLoc;

In my HUD class, I draw a 2d line from the center of the screen to the mouse location, but it does not work, it starts from a random point somewhat near the center, then goes off screen.

I have another FVector2D, it is the “Attack Mouse Position” (poor name), and it is the result of MouseLocation - CenterOfScreen. This should, in theory, give a vector that goes from the center of the screen to the mouse location. This does not work. What I am aiming for is that while the player is clicking the left mouse button, the game starts to capture the mouse’s location relative to the center of the screen. From that, I can determine which direction to attack in. Is there another way to determine the mouse’s location?

Ive done what youre trying to do in my game, but my approach is different.

I use GetHitResultUnderCursor to get the location of my mouse cursor, then instead of using the center of the screen to get direction, i compare the character location to the mouse location to get direction (For rotation you can use the UKismetMathLibrary::FindLookAtRotation)