RTS Selection Rectangle (revisited?)

I am very new at this (using Unreal for a few hours, generally like the interface so far).

I am trying to implement an RTS-style selection rectangle in C++. I’ve seen a few discussions/videos on implementation using blueprints but wanted to do this in C++.

Conceptually, what would be the best approach for this? This is what I think I need to do…

  1. In the editor, create a new MyHUD class that derives from AHUD

  2. In the editor, set MyHUD as the default HUD in Project Settings/Maps&Modes/DefaultModes. Also, you can overrides the Project Settings and set MyHUD as default HUD in World Settings/GameMode.

  3. In the source code, create MyHUD constructor in .h and .cpp (See 4.6 constructor changes, am confused - C++ - Epic Developer Community Forums).

  4. In the constructor, initialize HUD (eg, set fonts, etc.)

  5. (HOW TO DO THIS?) Override some sort of MyHUD:: onMouseButtonDown(mousex,mousey) callback function

  6. store mouse screen position as mousePt1(x,y)

  7. (HOW TO DO THIS?) Override some sort of MyHUD:: onMouseButtonRelease(mousex,mousey) callback function

  8. store mouse screen position as mousePt2(x,y)

  9. Deproject mousePt1 and mousePt2 into 3D world coordinates boxPt1_wc and boxPt2_wc. Use MyHUD:: Deproject(mousePt1X,mousePt1Y,pos_wc,dir_wc), compute boxPt1=pos_wc+dist1*dir_wc. Do same to compute second box point 2.

  10. (HOW TO DO THIS?) Call something like MyHUD::GetActorsInSelectionRectangle(boxPt1_wc ,boxPt2_wc,…) to get a list of all actors in the selection rectangle

  11. Now you have a list of all the actors, you can process this list as needed.

However, I saw some post which seemed to make this more complex.

Is my conceptual approach above the right strategy? Thanks for any help/suggestions you can provide!

I am not sure if this is the best solution but you can draw a rectangle in the UI and then do a GetAllActorsOfClass, loop through them pass in there location to ProjectWorldToScreen and use the result of that to check if it’s inside of the drawn rectangles area.