In my proyect I have a 3D widget which is attached to the camera and the player can spawn objects on top of it by selecting one of it’s buttons. However, I would like the widget to always be attached to the bottom of the screen (the lower bezel if you will).
I’ve have noticed that at different screen sizes, the widget will not scale correctly and I do not know how to make it so that it keeps it’s relative scale and position according to the screen.
For example, what I would like to accomplish is for my widget to be anchored to the bottom of the screen and occupy X percentage in height and another X percentage in width no matter the screen size.
Is there a way to accomplish this?
I think also a better question would be: Can I get the world position of the camera’s lower bound? that way I could anchor my widget to that position.
Here are a couple of screenshots, My widget is the thing with the greenish buttons.
This first one shows a small gap regarding the bottom of the screen
This one shows a huge gap with the bottom of the screen
Here’s how it works:
If its position remains relative to the screen then you do not want a Widget Component. You can do this all with a standard Widget.
Use anchors, as Everynone said, and Deproject Screen to World can be used to translate the 2D Widget Space to a 3D World Location: Deproject Screen to World | Unreal Engine Documentation
You may want to look into the ‘Scale Box’ Widget Layout as well.
If none of these are what you’re looking for then we’ll need some clarification.
Is there a reason you’re using a widget component for this? The whole point of having a component is that it can move automatically, follow a world coordinate and scale accordingly.
If you want a menu at the bottom of the screen, anchor it to the bottom edge using a canvas - it’s the appropriate tool for that kind of thing.
Do tell if I misunderstood your intentions here, though.
edit: Here’s how anchoring works:
Yes, please see my edited question at the end for a gif of how it works. Basically I want to spawn characters at the widget position which is something I’m already doing (don’t mind the clipping, I need to change the Z spawn pos). But I want this to happen in 3D, I want to be able to spawn these actors and in the future I’ll probably spawn particle effects and stuff like that. So as far as I know (which is not much) I can’t do that with a 2D widget, unless I replace the 3D models for textures but it’s not something I want.
It’s working fine, it’s just that I need to figure out how to position and size the widget or whatever I put there for aesthetic purposes
I need to figure out how to position
and size the widget or whatever I put
there for aesthetic purposes
I actually do not know how to do it from the top of my head. It would require a matrix transform of sorts. One that takes screen ratio, current resolution and object screen size into account - the latter BPs have no access to, for example.
You could hack it if you know the size will be fixed but it won’t.
So as far as I know (which is not
much) I can’t do that with a 2D widget
You absolutely can do it:
This is just a border.
Here’s a quickie that may work for you, at least consider the following:
- a Spawnbar widget anchored to the bottom of the canvas
- its widgets (border + sizebox) are in an array
- the buttons detect clicks and fire off an Event Dispatcher
- here in Level Blueprint but this belongs in the Player Controller or some kind of spawn manager
- above, we catch the dispatched event, spawn what’s needed and drive it around by hitting geometry
- the moving around can be done in many, many ways and you already have a solution so definitely stick to what makes it logical / comfortable
- you could easily decide which buttons spawn what as the dispatcher can be loaded with data
Even though it may not be exactly what you’re after, perhaps it will inspire you:
Sorry, I think there’s a confusion. My problem is not with actually spawning the actors and projecting the pointer to world space.
My problem is that I want the actors to actually be visible on top of the widget in the Z position when spawning them. Let’s say I also want to spawn a particle effect when the player clicks the button
If you see this gif, the actors are actually OVER the widget. In terms of functionality I’m already achieving what I wanted. I hope this makes it a little more clear, I think my question might be confusing and not representative of what I want to achieve.
I think we can generalize this question to How to anchor any actor to the bottom of the screen?
Let’s say in 3D card games, where the cards appear always on the bottom of the screen, how do they detect that lower bound?
Thanks for the answer, I think my question might be confusing and not representative of what I want to achieve. I’ve answered Everynone’s latest comment with some more clarification, if that helps
I see. Apologies for the misunderstanding.
Not sure how to solve this for all resolutions, aspect ratios and / or widget sizes. Widget components display their content on quads whose screenspace size will depend on many factors. Getting a screen space size of a 3d object is not exposed to BPs. And you will need this data for the calculations.
You’ll need to dig deeper into the engine. I had to do something similar a couple of times for aiming reticules and it wasn’t fun to work with. You can start with this perhaps:
This will give you the critical data for the screensize; you know the size of the widget component quad already. You would need to project it back to 2d while taking the camera frustum into account.
If there’s an easy way of achieving a perfect translation like this, I do not know it. It’s easy to do for a fixed size but seems like quite a challenge if you add just a handful of variables into the mix.
Thanks, I think that wil be enough to get me going.