Edit 2: All thanks to Everynone, I found out that in order to get the position of the element, I had to use its Canvas slot. Everynone’s last reply at the bottom of the page contains all the info necessary to set it up!
Edit: As a workaround I can just add scene components to the widget component Actor BP, though I would still like to know if it’s possible to get widget element world location (rotation too, if possible), since that seems to be more convenient.
I got a widget component as the base of an Actor BP, and I want to align 3d meshes into specific places relative to the widget (mesh rotation doesn’t matter, but widget rotation does).
Since widget components don’t have empties I thought I’d just use/place an image element on the widget and set the 3d mesh’s location to its, but it doesn’t seem like there’s any way to get the world location of it, or any widget elements.
2d widgets have screen location, 3d widgets have world location (although they can also render to screen via a switch in the panel). Since the 3d Widget is a component, it has all the usual transforms, world and relative:
Since widget components don’t have
empties I thought I’d just use/place
an image element on the widget and set
the 3d mesh’s location to its, but it
doesn’t seem like there’s any way to
get the world location of it, or any
widget elements.
Not sure if I follow, do you want to replace the embedded widget?
Thanks a lot for taking the time to help, and apologies for the bad explanation and lack of screenshots…
Shoulda mentioned is for a VR game. I also should’ve explained what I meant by widget element better.
Your help would solve the prob the way it’s currently worded (basically, “I wanna place 3d meshes relative to the widget”).
By widget element, I meant like an Image, Border, Button, Check Box, etc.
In reference to the following screenshot, I wanted to know if it’s possible to get the world location of that red dot (a “scaled down image” or whatever).
Currently, I have scene components parented to the widget component and it works. I was just kinda wondering/hoping? I could just get the world position of a widget’s image/border/button/whatever directly.
“you’d like to project widget element’s position into world coordinates”
Yes. But I’m pretty sure what I want is not as complicated as what you’re doing with the widget there. Are you moving an image element within the widget, or the widget itself?
In my case, I have an equipment menu (widget) that spawns at the location of the Vive controller when its shoulder button is pressed. I only change the widget’s rotation to face the player, leaving location and scale untouched.
When that 3d widget menu is created and placed in the world, I want to spawn 3d meshes at locations relative to the widget. Note: the widget’s rotation will vary depending on the position the vive controller was at relative to the player when the shoulder button was pressed.
Text elements = black + yellow, 3d meshes = green, and scene components = red.
I was able to make 2d/3d menu work by making an actor BP with the widget as the base, and then parenting scene components to the widget, but it seems kinda hacky to me. I was wondering if I could just use an image element or something instead of the scene component to get the location (to spawn the mesh at) from.
Yes. But I’m pretty sure what I want
is not as complicated as what you’re
doing with the widget there. Are you
moving an image element within the
widget, or the widget itself?
I think it was moving the entire widget, but moving just a widget element is very similar. I actually though you needed to manipulate the 2d widget within a 3d widget component and then use that relativity to spawn additional actors.
I was able to make 2d/3d menu
work by making an actor BP with the
widget as the base, and then parenting
scene components to the widget, but it
seems kinda hacky to me.
Sounds more than fine, to be honest. Just one thing, why do you need to parent anything? Could you spawn weapon meshes at the widget component location +/- offset? Or do the meshes need to be attached to the widget component after spawning.
I think I’m getting it slowly. Your 2d widget is shown above. And you want to spawn 3 meshes simultaneously and spaced exactly as the elements of the widget?
Sounds more than fine, to be honest. Just one thing, why do you need to parent anything?
Ah cool. Actually, I thought about spawning 3d meshes at offsets from the 2d widget’s location at first, but seeing as the widget’s rotation is derived from the vive controller’s yaw and the player’s location, I’d have to calculate that rotation into the offset. Math isn’t my forte, so I pussed out and went the route of having the scene components inherit the widget’s rot, and location, for me. I can easily get rel/abs location on the scene components from any actor.
Your 2d widget is shown above. And you want to spawn 3 meshes simultaneously
and spaced exactly as the elements of the widget?
Yes. That’s exactly it. I wasn’t really thinking of spacing them, though, rather just place them directly at an element’s location. Unfortunately, I couldn’t figure out how to access the world, let alone relative, location/pos of a widget element. I can’t even get the X/Y pos of an element from within the very event graph of the widget the element belongs to.
The following (blurry) ss is of the widget’s event graph. I tried to get the Menu_Image element’s location (searched for loc, pos, world, rel) but nothing comes up.
Afaik, an element’s loc (more accurately, X/Y position) seems only accessible via the widget animation editor (or the element’s Details panel). I hope I’m wrong!
Unfortunately, I couldn’t figure out
how to access the world, let alone
relative, location/pos of a widget
element. I can’t even get the X/Y pos
of an element from within the very
event graph of the widget the element
belongs to.
The following (blurry) ss is of the
widget’s event graph. I tried to get
the Menu_Image element’s location
(searched for loc, pos, world, rel)
but nothing comes up.
These three custom weapon widgets were added to a canvas panel:
For as long as something is a direct child of a canvas panel, you can get its relative position:
Do it for all 3 (in a macro/function), add an offset if you need to (screen space is cramped compared to the 3d world coordinates) and that should do it.
If you have any questions, do not hesitate to follow up.
@Everynone
Is it possible to somehow get the world coordinate of a widget element for a 3D widget? For example, I have a button that is part of a widget that is located somewhere in the world, I need to know the coordinate of this button in world coordinates.
Get the v3 world coordinate of the widget component. Then you’d need the get the v2 coordinate of the button within the geometry of its widget (gets more complex with a deeply nested hierarchy). You’d then transform the 2d offset from local to world and add it to v3.
I’ve assumed you’re using a widget component in world space and scaling has been done.
Hey, this seems to be similar to something I’m working on too. Could you give some clarification on the transforming the 2d offset from local to world step? Is that done manually, just by multiplying by whatever scale factor?