How to remove all widgets but one? Or, how to set origin to bottom right instead of top left?

I’ve been trying forever to find the answer to this by searching, trial and error, and nothing works. This is the other thing I’ve been stuck on for several days, and the other one I finally got the answer from some great people here, so I’m hoping that someone can help me figure this one out.

I’m working on a project for which the player walks through a large room, with some frames, that when the user hovers over them with the crosshair and clicks the mouse left button, a widget opens in full screen mode. When the user clicks on the right button, it closes and goes back to the level.

We achieved this by doing a line trace for each frame, and then for the right click, we used a “remove all widgets” node. And that works for the most part, except for this: we need a permanent overlay on the bottom right of the screen (like those network channels use, such as ABC, FOX, etc).

At first, we were using a widget for this permanent overlay, placing the graphic close to the bottom right. The problem came when we tried to use the “Remove from parent” node to perform the right click action to remove the widget from the screen and unpause the game. It worked in preview, but it gave the dreaded “accessed none” error. Unfortunately, there is a node called “Add to viewport” but there’s no node called “Remove from viewport”, at least in 4.23, which is what we have to use to be able to export to HTML 5.

So what I did as a workaround was to insert, in the HUD blueprint, a draw texture node, that comes from an “event receive draw HUD”, and try different numbers in X and Y to achieve the position that I wanted for that texture.

So I thought that was the perfect solution because it was a HUD texture and not a widget, so when the user right clicked and that triggered a “remove all widgets”, the overlay stayed on screen.

What I didn’t realized, until my coworkers told me, is that the size of the game is totally different depending on the computer and monitor size. So the numbers I had entered as X and Y, which in my case put the overlay texture like the typical network channel logo, in other cases was totally absent, or it appeared closer to the center of the screen, because the X and Y origin starts from the top left of the screen.

So that leaves me with two possible ways to solve this, and days of searching this forum and other websites, YouTube and whatnot, hasn’t given me yet:

  1. I find a way to change the origin from the default top left of the screen to the bottom right. This would be perfect.

  2. I set the overlay as a widget again, but then I have to find a way to prevent that widget from closing by using the remove from parent node, and variables for each of the widgets that I do want to remove from the screen.

  3. Some other way that probably I haven’t though of but more knowledgeable artists can tell me.

If anyone can give me any pointers I would be really grateful.

Remove from Parent is your go to here to remove specific widgets.

Resolving why that reference is invalid is what you should invest your time into fixing.

Get Viewport Size would get you the current size of the viewport and then you could scale your X & Y backwards. Get Viewport Size | Unreal Engine Documentation

I’d say the latter of the two solutions I gave is missing out on the default functionality of Anchors, Scaling, etc. that widgets take care of for you when you use Screen Size and shouldn’t be your permanent solution.

1 Like

Thanks, how exactly would I do that? I tried a few things but no luck. I don’t see a way to scale X and Y backwards. And doing it the way below, it shows in a different position if the preview window is a window as opposed to maximized.

1 Like

You were adding the set amount of pixels to get your texture in the correct spot in your original post, no?

Just subtract the texture size X from Viewport Size X and texture size Y from Viewport Size Y. This will put the texture fully visible but against the right/bottom limit of the viewport. Hopefully this steers you in the right direction. If you need it somewhere else then you just need additional math but Get Viewport Size will help you with the changing of monitors.

Like I stated though, widgets do this natively with anchors so it’s much easier just to do it that way.

1 Like

Well, the obvious solution was right in front of my eyes as it usually happens. What I did was simply to leave the remove all widgets node, but then connect the output to a create widget node to create the one that I had just removed. Problem solved.

Thanks everybody for their input though.