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…
-
In the editor, create a new MyHUD class that derives from AHUD
-
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.
-
In the source code, create MyHUD constructor in .h and .cpp (See 4.6 constructor changes, am confused - C++ - Epic Developer Community Forums).
-
In the constructor, initialize HUD (eg, set fonts, etc.)
-
(HOW TO DO THIS?) Override some sort of MyHUD:: onMouseButtonDown(mousex,mousey) callback function
-
store mouse screen position as mousePt1(x,y)
-
(HOW TO DO THIS?) Override some sort of MyHUD:: onMouseButtonRelease(mousex,mousey) callback function
-
store mouse screen position as mousePt2(x,y)
-
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.
-
(HOW TO DO THIS?) Call something like MyHUD::GetActorsInSelectionRectangle(boxPt1_wc ,boxPt2_wc,…) to get a list of all actors in the selection rectangle
-
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.
- Perhaps mouse callbacks can’t be implemented in the AHUD object, but need to be implemented in a PlayerController::LeftMouseButtonRelease()? I would guess I need to create create a C++ class from the Player Controller parent class? How do I set it to be used in my level/world/project? See GetActorsInSelectionRectangle on MouseRelease? - Programming & Scripting - Epic Developer Community Forums
Is my conceptual approach above the right strategy? Thanks for any help/suggestions you can provide!