# HUD - Get Actors in Selection Rectangle - Any way to improve on it ?

**URL:** <https://forums.unrealengine.com/t/hud-get-actors-in-selection-rectangle-any-way-to-improve-on-it/116134>\
**Category:** Blueprint\
**Tags:** unreal-engine\
**Created:** [September 10, 2018, 9:26pm UTC](https://forums.unrealengine.com/t/hud-get-actors-in-selection-rectangle-any-way-to-improve-on-it/116134 "2018-09-10T21:26:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarcoMariaRossi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/marcomariarossi/32/1069093_2.png) [@MarcoMariaRossi](https://forums.unrealengine.com/u/MarcoMariaRossi)\
**Post date:** [September 10, 2018, 9:26pm UTC](https://forums.unrealengine.com/t/hud-get-actors-in-selection-rectangle-any-way-to-improve-on-it/116134/1 "2018-09-10T21:26:45Z")

</div>

I have got a dragging, RTS style selection box working using the “Get actors in Selection Rectangle” but the results are really sloppy.  
I can be almost half a centimetre away from a mesh and it will still recognise and grab it. I understand this is because the node is reading the mesh bounds ?  
Is there a different, more precise way to do this ? Or a way to improve the node’s results ?

---

<div class="post-metadata">

**Author:** ![MarcoMariaRossi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/marcomariarossi/32/1069093_2.png) [@MarcoMariaRossi](https://forums.unrealengine.com/u/MarcoMariaRossi)\
**Post date:** [September 12, 2018, 9:34am UTC](https://forums.unrealengine.com/t/hud-get-actors-in-selection-rectangle-any-way-to-improve-on-it/116134/2 "2018-09-12T09:34:09Z")

</div>

I’m trying something different but I need some help.  
I found this formula and I thought to implement it in blueprint but i’m failing. Here is the formula:

(From: [algorithm - Finding whether a point lies inside a rectangle or not - Stack Overflow](https://stackoverflow.com/questions/2752725/finding-whether-a-point-lies-inside-a-rectangle-or-not))

 ![test2.PNG](https://d3kjluh73b9h9o.cloudfront.net/original/3X/5/8/588cab23d1a97f42fbcd2ec310b2542371615637.png)

and here is my blueprint interpretation:

 ![Math-test.PNG](https://d3kjluh73b9h9o.cloudfront.net/original/3X/9/3/934725850edcbdd3ebadbcfadac1b936152cf8f1.png)

What am I doing wrong ?

---

<div class="post-metadata">

**Author:** ![MarcoMariaRossi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/marcomariarossi/32/1069093_2.png) [@MarcoMariaRossi](https://forums.unrealengine.com/u/MarcoMariaRossi)\
**Post date:** [September 12, 2018, 1:18pm UTC](https://forums.unrealengine.com/t/hud-get-actors-in-selection-rectangle-any-way-to-improve-on-it/116134/3 "2018-09-12T13:18:37Z")

</div>

I managed on my own. Leaving this here for the people of the future (WARNING: i’m not a programmer):

 ![J1.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/0/0/005d474b84988e9a98de3acbaab985c7a83176f5.jpeg)  
 ![j2.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/8/e/8e58c516bfce5c6f245a469e811d72664015f105.jpeg)  
 ![j3.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/9/8/981c25a92728dc1f154995270d28b9d427ef460f.jpeg)

---

<div class="post-metadata">

**Author:** ![RobbiTheFox](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/robbithefox/32/835495_2.png) [@RobbiTheFox](https://forums.unrealengine.com/u/RobbiTheFox)\
**Post date:** [November 26, 2025, 11:30am UTC](https://forums.unrealengine.com/t/hud-get-actors-in-selection-rectangle-any-way-to-improve-on-it/116134/4 "2025-11-26T11:30:13Z")

</div>

This thread helped me a lot, thanks!

If anyone wants to do this in c++ (and a little more efficient, no offense!), here is what I did:

h

```cpp
FVector2D MultiSelectionStart;
FVector2D MultiSelectionEnd;
TArray<AActor*> MultiSelectionActors;
APlayerController* PlayerController;

// edit vectors so that A is top left and B bottom right
static void AllignVector2D(FVector2D& A, FVector2D& B)
{
	FVector2D C, D;
	C.X = FMath::Min(A.X, B.X);
	C.Y = FMath::Min(A.Y, B.Y);
	D.X = FMath::Max(A.X, B.X);
	D.Y = FMath::Max(A.Y, B.Y);
	A = C;
	B = D;
};
// check if A is "inside" B and C
static bool IsInRect(FVector2D& A, FVector2D& B, FVector2D& C)
{
	AllignVector2D(B, C);
	return B.X <= A.X && A.X <= C.X && B.Y <= A.Y && A.Y <= C.Y;
};

```

cpp

```cpp
GetActorsInSelectionRectangle(AActor::StaticClass(), MultiSelectionStart, MultiSelectionEnd, MultiSelectionActors);

// iterate back to forth, to prevent issues when removing entries
for (int32 i = MultiSelectionActors.Num() - 1; i >= 0; i--)
{
	AActor* actor = MultiSelectionActors[i];

	FVector2D screenPos;
	PlayerController->ProjectWorldLocationToScreen(actor->GetActorLocation(), screenPos);

    // remove actor from selection, if outside of selection rect
    if (!IsInRect(screenPos, MultiSelectionStart, MultiSelectionEnd))
        MultiSelectionActors.RemoveAt(i);
}

```
