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;
GEngine->GameViewport->GetMousePosition(MousePos);
FLinearColor PreviewColor = FPlatformMisc::GetScreenPixelColor(MousePos);
YagColorPreview->SetBorderBackgroundColor(PreviewColor);
YagColorPreview->SetColorAndOpacity(PreviewColor);
}
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.
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 outhttps://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Engine/UGameViewportClient/index.html