I have set up a Color Picker using a Slate button which has an image of different colors and when clicked sets a vector parameter I have set up in the Material Editor to change the color of an object.
It’s pretty straight forward and seems to work fine when running the game in the editor however when running in a standalone game I have 2 problems.
The Slate completely disappears from the in game screen after around 60 seconds.
When playing in full screen mode the FPlatformMisc::GetScreenPixelColor function I use passing in the current Mouse Position as parameters the only color that is ever returned is completely black yet in windowed mode or windowed full screen mode the correct colors are always found
I followed one of the few starter tutorial code samples I could find on slates the above code I posted is setup in the widgets class construct I then reference this widget in my HUD class.
Why you want to add WeakWidget to the viewport? SWeakWidget will be removed from memory if theres no reference to it during garbage collect. So if you really want to use WeakWidget keep a reference to it or just add your TestUIWidget to Viewport.
Edit:
I actually misunderstood concept of SWeakWidget so ignore this comment
Yes it is member variabled my TestHUD.h looks like this
UCLASS()
class ATestHUD : public AHUD
{
GENERATED_UCLASS_BODY()
TSharedPtr<class STestUIWidget > TestUIWidget;
void BeginPlay();
void DrawHUD();
};
Like I said the knowledge I had of Slates was basically just from the tutorial I followed however I have done more research on them now and well there seems to be a lot more to SWeakWidget than I originally thought.
In terms of just adding the TestUIWidget to the viewport I did try this
Also the widget will always remain there when playing within the editor so I’m wondering if it’s some sort of packaging issue? When playing in a standalone game the widget dissappears after a certain time yet when actually launching the game the widget isn’t there at all.
This is probably unrelated to your issue, but I noticed that UGameViewportClient::GetMousePosition is in client space, whereas FPlatformMisc::GetScreenPixelColor expects a screen space point.
This isn’t an issue when running the game in its own window, but will mess up the picking when running in an editor viewport.