[HELP] - Keeping UI element on screen

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
ZeroElementGames
Posts: 13
Joined: Tue May 25, 2021 7:18 pm

[HELP] - Keeping UI element on screen

Post by ZeroElementGames »

Hello there,

So I have a UI element in a Screen Space - Overlay render mode canvas. And I'm trying to keep it inside the screen boundaries. Since I am using the Bubble Template Standard UI Subtitle Panel prefab, that has two panels (Main Panel and Bubble Panel) with Content Size Filter & Horizontal Layout Group components, and I'm having a hard time getting the correct sizes/positions of the Bubble Panel (is the one that I want to keep inside the screen boundaries).

Do you have an idea of how to approach this issue?

Here's an image of what I'm trying to say:
Spoiler
cutUIElement.jpeg
cutUIElement.jpeg (141.71 KiB) Viewed 276 times

Thank you in advance!
User avatar
Tony Li
Posts: 22135
Joined: Thu Jul 18, 2013 1:27 pm

Re: [HELP] - Keeping UI element on screen

Post by Tony Li »

Hi,

That prefab was designed for a world space canvas. The Main Panel extends all the way to the left and right edges of the canvas. The Bubble Panel is anchored to the bottom center of the Main Panel and expands up to the width of Main Panel as needed. (You can make Main Panel narrower to limit the bubble's width.)

Since it's a world space canvas that sits above the character's head, it's hard to keep it entirely onscreen unless you move the entire canvas. You may prefer to code like in the UI Smooth Follow example on the Dialogue System Extras page. It uses a screen space canvas. But it doesn't check the bounds to keep the entire bubble onscreen. You can modify the UISmoothFollow script's MoveUI method to do that. This Unity forum post has example code to do that.
ZeroElementGames
Posts: 13
Joined: Tue May 25, 2021 7:18 pm

Re: [HELP] - Keeping UI element on screen

Post by ZeroElementGames »

Hi there Tony,

Thanks for your help, I had already seen the post you sent me. I couldn't make work any of the methods shared there.

Since I added to the Main Panel of Bubble Template Standard UI Subtitle Panel a script that positions the UI panel from a 3D space to 2D space (screen). So It seems that is on top of the actor but always on Screen Space - Overlay.

I found a solution that works super well. Here it is, in case somebody sees this thread in the future!
User avatar
Tony Li
Posts: 22135
Joined: Thu Jul 18, 2013 1:27 pm

Re: [HELP] - Keeping UI element on screen

Post by Tony Li »

Thanks! That's a nice script. It's on the roadmap to implement something similar in the Dialogue System as soon as time allows.
Post Reply