[Question] How to Get Mouse Coordinates and Print its XY value

Hello guys,

I’m currently working on a selection box/marquee selection like those seen in RTS games

So I think for the first step, I would have to get the mouse coordinate on where the drawing of the box will begin and ends

I need some help and guidance on how to print out the value of the X and Y coordinates to show that its running fine.

Do i have to modify this line of code in any particular way?

GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Is this running?"));

Here are the rest of the codes

bool ARTS_RealPlayerController::GetMouseScreenPosition(FVector2D& MousePosition)
{
#if PLATFORM_DESKTOP
	const ULocalPlayer* LocalPlayer = Cast(Player);
	if (LocalPlayer && LocalPlayer->ViewportClient)
	{
		MousePosition = LocalPlayer->ViewportClient->GetMousePosition();
		return true;
	}
#endif

	return false;
}

void ARTS_RealPlayerController::GetMouseCoordinate()
{
	FVector2D MousePos;
	FVector2D MousePosition;

	GetMouseScreenPosition(MousePosition);

	MousePos.X = MousePosition.X;
	MousePos.Y = MousePosition.Y;

	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Is this running?"));	
}

Thanks

“I need some help and guidance on how to print out the value of the X and Y coordinates to show that its running fine.”

One very easy way to get debugging info via the PlayerController class, which I use constantly! (its faster than looking over at my log)

is to send the info to the player console.

Here is my function for doing this, this only works in a PlayerController class:

I included versions for outputting an int32 and a float

void AVictoryGamePlayerController::Display(FString s)
{
	ClientMessage(s);
}

void AVictoryGamePlayerController::DisplayInt(FString Label, int32 TheInt )
{
	Label += " ";
	Label += FString::FromInt(TheInt);
	ClientMessage(Label);
}
void AVictoryGamePlayerController::DisplayFloat(FString Label, float TheFloat )
{
	Label += " ";
	Label += FString::SanitizeFloat(TheFloat);
	ClientMessage(Label);
}

#Press ~

to open the console and see the current info

this is great for me because it does not even appear on screen but its like an in-game LOG

Rama

Thanks Rama, managed to print out the mouse position now.

Thanks :smiley: