Get world location of viewport screen edge?

I’m trying to get the world location of the edge of the screen so that I can have attacks shoot from the edge of the screen. Anyone have any idea how to do this? I’ve tried the following.

But seams to always be slightly below centers of screen, which doesn’t seam correct. All the existing posts about this were for mouse location to world location, which isn’t what I need. I specifically need viewport.

If C++ is required and can’t do this from BP that’s also fine as I’ve a utility plugin for attack behavior that I can just add that to.

You can try a line trace from the camera, coaxial with the camera cone (rotated at the FOV angles)
Then you will hit the edge of the screen (in theory)

1 Like

Hello,

Have you tried using get viewport size, break the struct and divide by two. This would be distance to edge of the screen from middle of the screen. You could then add a small offset so you are few pixels away from screen edge.

I am away from PC right now, so I can’t test it right now.

If I don’t forget, I will test it later today.

I haven’t tried that yet, but that sounds like a great idea. The BP function is there for it as well, thank you!

Still not quite right.

This results in the following vector returned.

Issue is probably with Viewport Position != Screen Position I’m guessing. There’s no BP node for Viewport to Screen, but there is a Screen to Viewport.

Believe I may have got it. Took a page from converting mouse position to world position with plane line intersection and applied to translation of screen to world.

This gives me screen center. Maybe hard to see, but there’s a green square inside the character.

So if I can get screen center. I should be able to get screen edge with viewport size function then.

1 Like

Awesome, confirmed this works for all screen edge locations that I wanted. So if anyone needs this you can just use the above to accomplish it. Adjust that Screen X/Y you feed into DeprojectScreenToWorld and that’s all there is to it.