How does one draw a selection rectangle in world space rather than on the HUD?

Bottom Line Up Front: Is there a blueprint node that allows you to draw a selection rectangle in the world space, such that the rectangle’s top left and bottom right vertices’ (based on mouse position on start click and release click respectively) have their x, y coordinates bound to the world’s x, y coordinates, instead of the screen/HUD’s x, y coordinates?

I’d like to create a selection rectangle for an RTS style game. I’ve got the selection code down, but I can’t figure out how to draw the selection rectangle anywhere besides the HUD. HUD selection is fine, and I have it working, but it limits me to selecting only the actors currently visible in the viewport/on my screen. If I pan the camera while continuing to draw the selection rectangle on the HUD, as expected, the selection rectangle’s starting coordinate stays relative to the HUD, departing from the world position originally clicked immediately upon camera pan.

I asked a similar question a few days ago, but I’ve since realized that what I was asking for was impossible since my code was set to draw the selection rectangle on the HUD. If I could draw in the world space, I think my problem will be solved. I saw another question asking about drawing in worlds space, but their issue had nothing to do with addressing the drawn rectangle being bound to the HUD vice the world.

You can do it with a procedural mesh component.

You need to create two triangles, get the world coordinates of the first click (Point A) and continuously update the mouse position if you are holding down the key (Point B).

Assuming that you want the rectangle aligned to the world XY, calculate the position of the two additional points:
Point C and Point D

Draw the two triangles providing the vertices in the same order (both clockwise or counterclockwise), for example ABC and ADB, if you do it in a different order the normals should be flipped

1 Like

Thanks! I’ll do some research into procedural mesh components and report back.

Look at this post:

I showed how to draw a rectangle in world space with the mouse.
Also, it contains an example ue5 project.

My Products

Thanks to everyone who has replied, but the solutions provide so far don’t address exactly the issue I’m trying to get at, though they work in their own right. I finally found a good way to explain what I’m trying to do.

TL;DR
How do you make a selection marquee for an RTS style game that functions as the UE5 selection marquee in the blueprint event graph? See video.

Go into the event graph of one of your own blueprints, any will work but a larger, sprawling event graph with many nodes a better demonstration. Zoom in so that you can comfortable read the text on some nodes at the top left corner of the event graph, but such that there are nodes to the far right and down that cannot be seen at all. You can then left-click, hold and drag above and to the left of the visible nodes to start highlighting/selecting nodes from the top left. Keep dragging down and to the right (while keeping your zoom threshold constant) and you’ll notice that the rectangular selection marquee you are drawing doesn’t lock to the view port, but rather the top left corner coordinate where you first clicked and dragged from stays relative to the event graph itself (not relative to your own viewport). You can keep dragging and the rectangle still exists in the top left corner where you initially clicked. Drag until your furthest most right and down nodes are inside the selection marquee and then release your click. Nodes that are both visible in your current viewport of the event graph, as well as those that are no longer visible to you (because they are far to the left and up), where you first clicked get selected successfully. Every marquee tutorial I have watched creates a selection marquee that can only select actors currently in your game’s viewport, they cannot be dragged outside of the range of your viewport. If you drag outside your viewport, the selection marquee stays locked to your viewport and moves with the camera, meaning the maximum sized rectangle you can draw is the size of your viewport.

New Video link as the old one expired:

Finally found a work around. Not sure if there are performance implications associated with this technique, but it seems fine.

1 Like

Upon working through the method suggested in the video I posted above, I refined the methodology and combined the marquee selection capability with my RTS camera pawn. In the video, the author spawns a separate actor to be his marquee collision box, he setups the logic inside that actor and modifies that actor based on the mouse inputs from the player controller. I combined the authors actor with my camera pawn by simply adding a collision box to my camera pawn blueprint so that I didn’t need a completely separate actor. The collision box initially starts with no size and no collision at the same locations as the default root. See below for the blueprint event graphs I used to de-clutter and consolidate the author’s method. I also got rid of the event tick and setup an event timer by function so that the marquee isn’t constantly computed every tick, but rather only while the trigger event is firing. I have not yet added a HUD component that shows where my collision box is, I’ve just left the collision box as “visible” and un-checked “hidden in game” for now. I’ve used the enhanced inputs with “Started” as on-left-click, a “Hold” functionality applied to “Triggered”, and I left click-released alone as “Completed”.