How do I create a 3D seletion from a 2D hub box

I’m creating a RTS, in this I would like to make a selection of character on screen, I would draw a rectangle on screen and then have the system select all of the pawns within the rectangle box.

My problem is the rectangle is made in 2D on the HUD like this:

Now I’m a little stuck on how to select the character in 3D. At the moment I have spawned a box collision at the centre point and the scaled it based on size of the rectangle. This looks like this:

This is really inaccurate. I was toying with ideas of making multiple box tracing but I think their must be a better less hacky way to do this.

Are you using this:

299568-annotation-2020-04-12-085312.png

The inaccuracies you describe stem from not accounting for the viewing frustum. As in, the 2d rectangle is not representative of the corresponding trapezoid in 3d space.

No Looks perfect I’ll give it a try.

Since HUD seems mostly redundant these days, almost forgotten as it’s been replaced with UMG, here’s an example of how it can be made work:

  • create a HUD class and assign it to your Game Mode
  • one could call HUD like so:

  • and the implementation:

[edit] - above, the Draw Rect should be connected to the For Each Loop’s Completed pin, of course.

Image from Gyazo

Thanks so much Everynode

Bunch of stuff their I never knew about.

I’m having trouble implementing it with my present set up. I have got the "D begin and end of the selection but I can’t get it to return any of the actors in the selection.

This is what I have done.

Thanks again, really appericate this!

Are you running this in the HUD class? It looks like you are not. You need to run this using the HUD’s draw call. You should be bombarded by warning messages in the output log.

The code is in the player pawn.

It’s a unique feature of the HUD class as mentioned above, hence me uploading an example as it is a bit obscure. There are bits of functionality in the engine that require specific world context to run, this is one of them.

~Thanks I’m redoing it now. :slight_smile: