HUD - Selection Rectangle for RTS style game


I’m having a hard time visualizing how I would put together a selection rectangle in Unreal Engine 4. (Left click and drag creates rectangle -> all “units” in the rectangle bounds are selected)

Here is my first attempt just trying to get a hard coded size rectangle to draw on the screen.

Anyone have any suggestions on how to proceed? Am I going about this the entire wrong way? Should the entire HUD size be a Hitbox instead?

Note: I searched and didn’t see any solutions to this issue so wanted to create a thread for when the problem is resolved there is a reference. The HUD documentation is basically 0 right now so I can’t even try to struggle through it.


no idea how to help YET… but I am just digging into the same thing myself and was thinking maybe a bunch of us need to band together and create a generic RTS toolkit or something of that nature.

You want draw it on de HUD or in game space?

For teh hud make macro that draws a box around certain 2d coordinates of your cell. Ie. calculate position on hud fro cell location then draw 4 sticks around.

For game thisw should be quite similar. Make wall static mesh that has width equal to your in game cell size and has pivot or offset equal to half size.
So when rotated around pivot it snaps to sides (walls off cell). Then make blueprint that shows/spawns those walls for cell. Make walls no colision and transparent and you have it in game space.
instead of walls you can use decals, ot you can make material that uses pixel depth and displays glowing line only in places where wall intersects with other object.

Such stuff should be done as plugin in C++.

Hey brettclutch, hopefully this helps, it’s a HUD Blueprint that assumes you’re using the default flying pawn, and it has the basic look/movement setup enabled (check the Pawn’s “Defaults” page and you should see that option, it’s enabled by default). I am also using a local Vector2D variable on the HUD BP called “Selection Start”, which as you can see, I set once when the drag starts, and it basically just maintains the reference to where you started dragging from.

Right now, it’s checking for the left mouse button down condition on the Draw HUD event, and it will force disable Look Input (by default you can left click and drag around to free look), then draw a line from where you started to whereever you drag.

It’s very simple to go from here and create a box, just render more HUD lines, swapping the X and Y coordinates of the mouse’s Screen Position Vector2D. For example, if you dragged from {0,0} to {100,100}, you could draw a line sequence like {0,0} -> {100,0} -> {100,100} -> {0,100} -> {0,0}, and you’d have a complete box!