Okay, no problem. I was there too
- Drawing dots on your collide box is a very good step. You clearly see where are drawn extends of your objects. Those extends are important, because we choose 4 from them:
- The highest
- The lowest
- The one furthest on the left side of the screen
- The one furthest on the right side of the screen
In the next step we merge these points. The points in 3D space are converted to 2D space on your viewport. Top left corner of your viewport is a point XY (0,0) and bottom right corner of your screen in editor is XY (Max Resolution X, Max Resolution Y). For example resolution of my viewport is 1280x720, so bottom right corner will be XY (1280x720).
We merge points by combining their X and Y coordinates.
For example (picture below):
- The highest point is the blue one so we take it’s Y (the smallest Y),
- The furthest left is green point, so we take it’s X (the smallest X),
- The furthest right is orange, so we take it’s X (the biggest X),
- The lowest point is a red points, so we take it’s Y (the biggest Y).
So the TOP LEFT corner will be Blue_X, Green_Y,
the BOTTOM RIGHT corner will be Orange_X, Red_Y
And as you can see, green+blue+orange+red lines create a rectangle, which in the end is known as the Bounding Box.
2. To add Actor input to your widget or any other variable
you need to get inside of the Widget Blueprint and ADD the variable and select few checkboxes. In our case it’s an Actor variable type with the same name. But If you want an Integer or something other than Actor then the rule is the same.
After you selected the Actor variable type, select:
- Instance Editable,
- Expose on Spawn,
Instance Editable is required if you want to have an Input to your widget and allows you to edit your variables if you would like to use your widget by another actor for example.
Expose on Spawn on the other hand is a target of your question. By exposing variable we treat it as an input to that widget
After we checked boxes hit Compile and save. Now, go back to your object where you want to input your Actor.
If you don’t see Inputs press Right click on the Create Widget node and hit REFRESH NODES.
If your Variable is “Actor” then you should connect Actor itself, that’s why do a right click in the free space of the blueprint and type “Self”. You should be able to find “Get a reference to self”. Click it, connect it to the Actor input we just created and that’s all!
// As you can see I allowed myself to Expose even more variables like ID, Hours, Minutes and so on (Integer variables).
//Make sure you connected all “Add to viewport” node otherwise you won’t see anything on your screen.
If you haven’t modified much code provided by @lan, then it should pretty much work from now on. Just make sure you don’t use “Simulate” to test bounding boxes.
3. Function OnPaint is an override function. It works ALL THE TIME. You don’t have to worry about connecting it or calling it, because that function just does it alone by itself constantly.
If your Bounding boxes are correctly calculated then you’ll see a rectangles through your map if you face your target object with your viewport camera.
If your Bounding boxes are not correctly calculated then you won’t see any drawings, but in real scenario they will be still calculated and drawn.
Hope it helped
- I forgot to mention that Top left corner of the Bounding Box is called (in a code) “BoxStart” and it has the smallest X and Y.
“BoxEnd” is the Bottom Right corner of the Bounding Box which is known as the biggest X and Y. Good luck!