# UMG Widget: Stay on screen - But how?

**URL:** <https://forums.unrealengine.com/t/umg-widget-stay-on-screen-but-how/123044>\
**Category:** Blueprint\
**Tags:** unreal-engine\
**Created:** [March 2, 2019, 4:07pm UTC](https://forums.unrealengine.com/t/umg-widget-stay-on-screen-but-how/123044 "2019-03-02T16:07:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![polygon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@polygon](https://forums.unrealengine.com/u/polygon)\
**Post date:** [March 2, 2019, 4:07pm UTC](https://forums.unrealengine.com/t/umg-widget-stay-on-screen-but-how/123044/1 "2019-03-02T16:07:47Z")

</div>

Hi,

I’d like to align a 2d widget to an actor. To do this, I added the widget to a canvas and I’m setting it’s canvas panel slot’s position in the tick function. This works very well to a certain point.

As you can see in the attached image, if the actor is too close to the edge of the screen, the widget gets clipped and a part of it moves out of the screen. I want the widget to stay on screen without being clipped and constrain it to the player’s screen. Is there a simple way to achieve this behaviour?

 ![widgetscreen.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/6/e/6ea660df8e7f2ec0043d17aa1cac8cbca023617a.jpeg)

Thanks in advance and kindest regards,  
Daniel

---

<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:** [March 2, 2019, 4:27pm UTC](https://forums.unrealengine.com/t/umg-widget-stay-on-screen-but-how/123044/2 "2019-03-02T16:27:21Z")

</div>

Yup, before setting its position, check viewport / canvas size and subtract the widget size - that’s your clamp.

---

<div class="post-metadata">

**Author:** ![polygon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@polygon](https://forums.unrealengine.com/u/polygon)\
**Post date:** [March 3, 2019, 10:27am UTC](https://forums.unrealengine.com/t/umg-widget-stay-on-screen-but-how/123044/3 "2019-03-03T10:27:51Z")

</div>

Thank you so much for your quick reply! It works like a charm and saved me so much time! 🙂

---

<div class="post-metadata">

**Author:** ![dudusstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dudusstar/32/753224_2.png) [@dudusstar](https://forums.unrealengine.com/u/dudusstar)\
**Post date:** [November 18, 2020, 11:23am UTC](https://forums.unrealengine.com/t/umg-widget-stay-on-screen-but-how/123044/4 "2020-11-18T11:23:50Z")

</div>

> [@polygon](#):
>
> Thank you so much for your quick reply! It works like a charm and saved me so much time! 🙂

Hi! I want to do the same but I have no idea how. Can you show me your blueprint solution? Thank you!!

---

<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:** [November 18, 2020, 12:11pm UTC](https://forums.unrealengine.com/t/umg-widget-stay-on-screen-but-how/123044/5 "2020-11-18T12:11:17Z")

</div>

> [@dudusstar](#):
>
> Hi! I want to do the same but I have no idea how. Can you show me your blueprint solution? Thank you!!

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:

 ![Screenshot 2020-11-18 120640.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/c/4/c44cc490fd30e71d37f8c7c129bb4333f20b33eb.jpeg)

vid: [https://i.gyazo.com/7e60baa21a0fbe5e5796d81524b27671.mp4](https://i.gyazo.com/7e60baa21a0fbe5e5796d81524b27671.mp4)

---

<div class="post-metadata">

**Author:** ![dudusstar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dudusstar/32/753224_2.png) [@dudusstar](https://forums.unrealengine.com/u/dudusstar)\
**Post date:** [December 8, 2020, 8:20am UTC](https://forums.unrealengine.com/t/umg-widget-stay-on-screen-but-how/123044/6 "2020-12-08T08:20:18Z")

</div>

Wow! Purrrfect, thank you!

---

<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:** [September 22, 2023, 4:14pm UTC](https://forums.unrealengine.com/t/umg-widget-stay-on-screen-but-how/123044/7 "2023-09-22T16:14:48Z")

</div>

I also use Anchor Widgets when it makes sense as they have an option to select to stay in viewport
