I came recently from Unity world, and I felt that UMG is somewhat similar to Unity UI, but more powerful.
But UMG programming seems to be more complicated than I expected.
I need to do a very basic task. I have a simple hierarchy of Canvas Panel and a child image. I just want to scale the child image to the screen size no matter what resolution changes.
I understand I can just use anchors to the corners of the screen and I will get it working, but I want to understand how size works in UMG for more advanced task I want to do after this.
Here is my dead simple setup
In the designer, setting image size to 1920x1080 while having the anchor at left-upper corner seems to do the trick.
But when I play the game in the viewport I see black borders, or extending image beyond the view depending on the viewport size. (I tried to attach an image of how it looks in playmode, but the forum gives me <p>Database Error</p>)
I tried writing this code in my C++ widget class, and setting the comicImage->Slot size to viewport size, resolution size, ratio size, and it’s always wrong. comicImage is a pointer to the Image in the hierarchy.
I want to understand what coordinates does the UCanvasPanelSlot::SetSize method use, also what is the x,y coordinate for the lower-right corner of the widget?
UCanvasPanelSlot* imageSlot = dynamic_cast<UCanvasPanelSlot*>(comicImage->Slot); FVector2D ViewportSize = FVector2D(GEngine->GameViewport->Viewport->GetSizeXY()); FVector2D Resolution = FVector2D(GSystemResolution.ResX, GSystemResolution.ResY); FVector2D newSize(Resolution.X * DesignTimeSize.X / ViewportSize.X, Resolution.Y * DesignTimeSize.Y / ViewportSize.Y); imageSlot->SetSize(newSize); //setting it to ViewportSize or Resolution, also gives weird results
Thanks for advance.