# Constrain UMG widget inside player screen

**URL:** <https://forums.unrealengine.com/t/constrain-umg-widget-inside-player-screen/59622>\
**Category:** Blueprint\
**Tags:** unreal-engine\
**Created:** [March 29, 2016, 2:07pm UTC](https://forums.unrealengine.com/t/constrain-umg-widget-inside-player-screen/59622 "2016-03-29T14:07:05Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ClaudioPiccinni](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ClaudioPiccinni](https://forums.unrealengine.com/u/ClaudioPiccinni)\
**Post date:** [March 29, 2016, 2:07pm UTC](https://forums.unrealengine.com/t/constrain-umg-widget-inside-player-screen/59622/1 "2016-03-29T14:07:05Z")

</div>

Hi all,  
I’ve been messing around with UMG trying to create a menu that pops next to the mouse location. I got it to work almost like intended using ‘Get Mouse Position’ and ‘Set Position In Viewport’ nodes.  
What I’m not being able to do is finding a way to keep the widget inside the player screen when you click for example in the lower, or right, portion of the screen. The picture shows what I mean, the current behavior (1) and the desired (2).  
I don’t know if there are any built-in settings/nodes to do it, maybe playing with anchors?  
Any help is much appreciated.  
Thanks.

![84236-untitled.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/1/e/61e72db17e797c4f0457d1befe48c0765d0137bf.png)

---

<div class="post-metadata">

**Author:** ![ClaudioPiccinni](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ClaudioPiccinni](https://forums.unrealengine.com/u/ClaudioPiccinni)\
**Post date:** [March 30, 2016, 1:08pm UTC](https://forums.unrealengine.com/t/constrain-umg-widget-inside-player-screen/59622/2 "2016-03-30T13:08:19Z")

</div>

Does anyone have an idea at least that could potentially set me on the right track?

---

<div class="post-metadata">

**Author:** ![Urm92](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Urm92](https://forums.unrealengine.com/u/Urm92)\
**Post date:** [March 30, 2016, 2:02pm UTC](https://forums.unrealengine.com/t/constrain-umg-widget-inside-player-screen/59622/3 "2016-03-30T14:02:38Z")

</div>

Try to calculate a bit around.

PlayerController -\> GetViewportSize  
Widget -\> GetDesiredSize

So if you press your mouse you get the location and add the x/y of your widget, if its bigger than your viewport x/Y you subtract what ever amount you want and set is as desired location.

---

<div class="post-metadata">

**Author:** ![ClaudioPiccinni](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ClaudioPiccinni](https://forums.unrealengine.com/u/ClaudioPiccinni)\
**Post date:** [March 31, 2016, 4:40pm UTC](https://forums.unrealengine.com/t/constrain-umg-widget-inside-player-screen/59622/4 "2016-03-31T16:40:38Z")

</div>

Hi Urm92, thanks for the hint. I thought about doing something similar, but I’m having difficulties when resizing the window/viewport. I think it has to do with the change in resolution or ui’s dpi. The widget appears slightly in the wrong position.

---

<div class="post-metadata">

**Author:** ![NickDarnell](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NickDarnell](https://forums.unrealengine.com/u/NickDarnell)\
**Post date:** [April 1, 2016, 2:08pm UTC](https://forums.unrealengine.com/t/constrain-umg-widget-inside-player-screen/59622/5 "2016-04-01T14:08:34Z")

</div>

I recommend the helpful functions, AbsoluteToViewport, LocalToViewport, GetViewportScale, GetMousePositionScaledByDPI, ProjectWorldLocationToWidgetPosition. Lots of helpful utility functions for figuring out the right location in widget space that takes DPI scale into account.

---

<div class="post-metadata">

**Author:** ![ClaudioPiccinni](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ClaudioPiccinni](https://forums.unrealengine.com/u/ClaudioPiccinni)\
**Post date:** [April 5, 2016, 10:55am UTC](https://forums.unrealengine.com/t/constrain-umg-widget-inside-player-screen/59622/6 "2016-04-05T10:55:17Z")

</div>

Hi Nick, thanks for the clarification.  
I can’t find much on the first two functions you mentioned. Are there examples, or tutorials, or official documentation, really anything that can help me grasp the underlying working?  
Even a few words explanation of how it works would be awesome.  
I also can’t find anything that explains the differences between “Desired”, “Desired on Screen”, “Custom”, “Custom on Screen” anywhere, but maybe I’m serching in the wrong places.  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Vyks](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Vyks](https://forums.unrealengine.com/u/Vyks)\
**Post date:** [August 25, 2021, 6:04pm UTC](https://forums.unrealengine.com/t/constrain-umg-widget-inside-player-screen/59622/7 "2021-08-25T18:04:38Z")

</div>

> I also can’t find anything that explains the differences between “Desired”, “Desired on Screen”, “Custom”, “Custom on Screen” anywhere, but maybe I’m serching in the wrong places.  
> Thanks in advance.

Did you find out ?  
I’m looking to know as well

---

<div class="post-metadata">

**Author:** ![ClaudioPiccinni](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ClaudioPiccinni](https://forums.unrealengine.com/u/ClaudioPiccinni)\
**Post date:** [August 26, 2021, 12:50pm UTC](https://forums.unrealengine.com/t/constrain-umg-widget-inside-player-screen/59622/8 "2021-08-26T12:50:07Z")

</div>

At some point in these five years I found out that those options can be used to choose the overall size of the layout relative to the screen size.

Fill Screen = the layout will always be the size of the screen it’s on.  
Custom = you can specify a size for the layout regardless of the screen it’s on.  
Custom on Screen = same but there is an additional outline for the screen size.  
Desired = layout is large just enough to fit all of the widgets within it while still maintaining the spacing set by the Anchors.  
Desired on Screen = same but you can also see the edges of the screen

Hope it helps!

EDIT: a couple of helpful links when starting out with umg resolutions and scaling:

> **[UMG Best Practices](https://docs.unrealengine.com/4.26/en-US/InteractiveExperiences/UMG/UserGuide/BestPractices/)**
>
> Tips and Tricks for working with Unreal Motion Graphics.

> **[Scale UI for Different Devices](https://docs.unrealengine.com/4.26/en-US/InteractiveExperiences/UMG/HowTo/ScalingUI/)**
>
> Shows how you can set up your UI to scale to different devices automatically using DPI Scaling.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 26, 2021, 1:02pm UTC](https://forums.unrealengine.com/t/constrain-umg-widget-inside-player-screen/59622/9 "2021-08-26T13:02:58Z")

</div>

> [Constrain UMG widget inside player screen](https://forums.unrealengine.com/t/constrain-umg-widget-inside-player-screen/59622)

There are many ways:

> [@UMG Widget: Stay on screen - But how?](https://forums.unrealengine.com/t/umg-widget-stay-on-screen-but-how/123044/5):
>
> while there’s half a dozen ways to implement this, the gist is to subtract half the widget size from the viewport size and use it as a clamp: vid: [https://i.gyazo.com/7e60baa21a0fbe5e5796d81524b27671.mp4](https://i.gyazo.com/7e60baa21a0fbe5e5796d81524b27671.mp4)

There’s also automatic tooltips that do this automagically. There’s also menu anchor widget that can pop something - afair, it respects screens boundary, I migth be wrong about the last one, though.

* * *

> [@Vyks](#):
>
> I’m looking to know as well

These are just for to preview the widget in the Designer. It gives you a reasonable idea of it will behave, so it’s easier to work with. Think of those modes as simulation.

This widget does not have a parent atm, but if you’re planning on placing it in a container like a 64x64 Size Box or Canvas that will enforce the Desired Size, you could set Custom On Screen to 64x64 as well. Now the widget will behave as if it was sitting in a restrictive parent even though it’s yet to be added there.

---

<div class="post-metadata">

**Author:** ![Kiwi2703](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kiwi2703](https://forums.unrealengine.com/u/Kiwi2703)\
**Post date:** [June 22, 2023, 10:56pm UTC](https://forums.unrealengine.com/t/constrain-umg-widget-inside-player-screen/59622/10 "2023-06-22T22:56:43Z")

</div>

If someone is still looking for an easy solution, you can use this:

 ![keepwidgetonscreen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/9/1/891169c819e67bcf00b87b2e6a2161aa2b30ea74.jpeg)

---

<div class="post-metadata">

**Author:** ![blindminds](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/blindminds/32/1213160_2.png) [@blindminds](https://forums.unrealengine.com/u/blindminds)\
**Post date:** [October 5, 2023, 6:24pm UTC](https://forums.unrealengine.com/t/constrain-umg-widget-inside-player-screen/59622/11 "2023-10-05T18:24:09Z")

</div>

This was my solution…

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/0/0/b00225962aab3172acdfe6d3b35355bc69e0df60.jpeg)  
[Sample Video](https://youtu.be/jE1iQkMr4ik)

Everything else i tried from others suggestions did not work except this.  
Hope it helps!
