UMG Widget: Stay on screen - But how?

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?

Thanks in advance and kindest regards,
Daniel

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

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

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:

vid: https://i.gyazo.com/7e60baa21a0fbe5e5796d81524b27671.mp4

6 Likes

Wow! Purrrfect, thank you!

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