Get Actors in Selection Box Problem

Hi! :slight_smile:
I created a RTS selection rectangle and the unit selection doesn’t work perfectly…
This is the selection BP:

And this is the result with the problem: (if it moves slowly, click on the 3 dots icon in the right side and change it to MP4)

As you can see, when the selection box is too small, the actor is still unmarked even if the selection box exactly on the actor.
So how can I fix this?


1 Like

Someone help please? :\

Uncheck “Actor Must be Fully Enclosed”?

I tryed it and it still doesn’t work perfectly…

Another problem that comes with it:

This node was contributed by rama, maybe he can help.

Check this out first…

I was having some problems with the selection box as well but managed to find and solve the issue. Here are some things to note:

-The “GetActorsInSelectionRectangle()” method needs to be invoked within the HUD::DrawHUD() method. If you dig into the C++ code implementation, there is this code:

FBox2D ActorBox2D(0);
for (uint8 BoundsPointItr = 0; BoundsPointItr < 8; BoundsPointItr++)
   // Project vert into screen space.
   const FVector ProjectedWorldLocation = Project(BoxCenter + (BoundsPointMapping[BoundsPointItr] * BoxExtents)); //<---Look in here!
   // Add to 2D bounding box
   ActorBox2D += FVector2D(ProjectedWorldLocation.X, ProjectedWorldLocation.Y);

There is some internal validation checking which happens when you project an object. It checks to see if a Canvas object is not null. The only time the canvas object is not null is when you’re using the DrawHUD() method. So! That certainly puts some limitations on when and where you can call the method!

-The class can also use class filters, if you set any. If you don’t set any or use a very broad filter, you’re going to get a lot of hit results which you then have to filter manually. Internally, the class just takes all objects in the game world, unprojects them into screen space, and then does a 2D bounding box collision test against the actors bounding area. SO! If your actor doesn’t actually HAVE a bounding area, a bounding box can’t be derived and you won’t ever get any hit results! Make sure your bounding area exists and is where it should be (hint: turn on the bounding area visibility for testing/debugging).

-Last resort: You can always set a breakpoint in the C++ code and step into the selection box code. Does the world contain the object you’re trying to select? Did you accidentally filter it out before you do the selection results? Does the object have a bounding area? Do you have a canvas? Does the selection box actually overlap the unprojected bounding box?

-If things are still super crazy and the unprojection is still wrong, you want to verify that you’re actually unprojecting with the correct camera! A camera has an internal View Projection matrix (stored within the UCanvas object [Canvas.h, line 210]) which it uses to unproject things from 3D space into 2D space. If you’ve got two cameras in different positions, and you’re sending your selection rectangle drawn in your current camera to an inactive camera, the deprojection is going to be wrong and you’re going to be selecting objects which aren’t in your current view or selection box. I don’t know how you’d accidentally do this, but its possible.