How should i use GetScreenPixelColor?


I am trying to use FPlatformMisc::GetScreenPixelColor on a SColorSpectrum to make a color picker.

I am using the following code. YagColorPreview is a SButton that is supposed to be colored with the picked up color.
This function is called when the SColorSpectrum is clicked.

// set player color preview
void AYagHUD::SetYagPLayerColorPreview()
	FVector2D MousePos;
	FLinearColor PreviewColor = FPlatformMisc::GetScreenPixelColor(MousePos);

The problem is that when clicking on the color picker (SColorSpectrum) i pick up random colors (mostly shades of gray) instead of the color i am clicking on.

What am i doing wrong ?



Ok, got my answer from here:

The trick was to use:

FIntPoint MousePos;
GEngine->GameViewport->Viewport->GetMousePos(MousePos, false);

I kind of suspect it picks color from entire system screen not just game output (which in UE terminology it would be called viewport) and you need to add window position in to mouse position which is relative to game viewport. Looking up in to viewport classes might also help you out


You guessed right :slight_smile:

I just posted the answer (which i found in another post) just a few minutes ago, probably while you were writing your answer.

Thanks though lot for taking the time to read & answer.