Set image position inside widget through widget interaction component

I will try to describe what i am trying to do. I have a image which will simulate mouse cursor inside 3d widget.
1 problem left here. How to convert widget interaction component hit result to position inside widget. I have no idea how to convert them. Or maybe i do it absolutely wrong.

Hello Pr0t0Ss12,

After taking a look at your thread I was able to create a quick example to get you started in the right direction. I hope that this information helps.

Example:

Here I have created a new widget with two images in it. One will be used to follow the mouse (the green one) and the other is simply a background to make the 3D widget component easier to see. I set the image’s alignment to be (0.5, 0.5) so that it centers itself on the mouse’s point.

Here I have created an actor blueprint and I have added a widget component to it. From there I set the draw size to that of my widget (1920 by 1080) and I have set the pivot point to 0,0. The pivot change will be needed so that the actor location becomes the top left corner of the widget component (screen position is calculated form the top left corner to the bottom right). This will allow us to use the widget components relative location to determine where exactly the hit location is in relation to the widgets surface.

Here I have used the first person character blueprint to interact with my widget. I added a widget interaction component. I increased the interaction distance for easy testing. I also set the interaction source to “Mouse”.

From there I get the hit result from the widget interaction component. This allows me access to the hit location and the actor (3Dwidget) location. I convert the hit location to a relative location as it relates to the 3D widget. Once I have the relative location. I vet the vector length of the x and y of the hit location. This give me the horizontal distance from the 3D widgets relative location (creating what will be the screen space equivalent of the X axis). I then combine this with the Z value of the relative hit location. This gives me the relative vertical distance (creating what will be the screen space equivalent of the Y axis). Once I have my Screen space position equivalents, I create a 2D vector to hold them and cast to the widget that is being used so as to set the position of the image.

Notes:

The math will have to be changed if the widget is scaled. You will need to adjust the “screen space” values by the same scale.

This setup will handle all changes in yaw but does not take into account pitch or roll. However, this is an example to get you started.

Make it a great day

Hey!

Hey Rudy! Thanks a lot for your answer, I’ve actually gone ahead an found another way of achieving this goal based on what you’ve proposed, but this new method does not suffer from the limitations you’ve noted.

I’d like to share it here for anyone else reading this post.
It turns out the Widget Interaction Component has another output that gives you the relative XY position of your hit in the widget’s space,which is just what we need!

I’ve been using this method as a way to make a tooltip (child/nested) widget follow the hit location of the interaction component inside a talent tree (parent) widget - in VR.

Which brings me to my next point:
I would like to request that support for “Custom Tooltip Widget” which already exists as a feature for blueprint widgets also be added to blueprint widgets which are not added to the player’s viewport (which is almost always the case in VR content), that would’ve saved me literally hours of work trying to find workarounds for such a commonly used feature.
I’m sure VR devs would really appreciate that.

Note: this method was achieved using UE4.15.1 and might not have been available at the time you made your reply.

Some images to drive the point home:

139955-widgetinteraction2dhitlocationnode.png

Yes) I solve this by same way, this new node helps me a lot.

This solution worked perfectly for my scenario, thank you so much!

Works absolutely perfect.