i want to make an rts and iam currently working on rectangle selection. And unreal provides me with the GetActorsInSelectionRectangle . Wich is great but i have no idea how to use it. The Documentation doesnt really help me. So how can i use it ?
I think that you may confuse it you is output refrence argument, it a way to make functions with multiple output data, in this case, return bool and array actors that been found, so:
template<typename ClassFilter>
bool GetActorsInSelectionRectangle
(
const FVector2D & FirstPoint,
const FVector2D & SecondPoint,
TArray< ClassFilter * > & OutActors,
bool bIncludeNonCollidingComponents,
bool bActorMustBeFullyEnclosed
)
First 2 is ofcorse from-to points of squere, FVector2D is like FVector just 2 dimensional, thing is they are laso refrences (& symbol) so you need create them extrnally or put refrence of other varable, 3rd is refrence argument which i mentioned, to use it you need to create empty TArray and place it as argument which function will fill with actor pointers of specific class on which later you can operate on, 2 last bools say by it self what the for. Function also got type template, which not only works as class filter but also let that array argument accept matching type of array as arrays got template too. So let say you want to get some pawns from random squere region on screen:
TArray<APawn*> Out;
FVector2D A = FVector2D(50,50);
FVector2D B = FVector2D(100,100);
if(GetActorsInSelectionRectangle<APawn*>(&A,&B,&Out,true,false)) {
for(APawn* i:Out) {
i->DoSomething();
}
}
Note that i also placed if which utilize bool return of function, this way you cna skip loop or other things if actors won’t be find. A and B you can replace with some varable wich i bet you already have, just pass refrence of them same as i passed refrence of A and B using & prefix
first of all thanks for you awnser. but it still dosent works. even if i use your code.
void ARTSHUD::RectangleSelection()
{
if (world)
{
if (con)
{
player = Cast<APlayerCameraController>(con->GetPawn());
if (player){
FVector2D firstPoint = player->FirstPoint;
FVector2D secconPoint = player->SeccondPoint;
TArray<APawn*> foundActors;
//Draw Rectangle
DrawLine(firstPoint.X, firstPoint.Y, secconPoint.X, firstPoint.Y, FLinearColor::Red);
DrawLine(firstPoint.X, firstPoint.Y, firstPoint.X, secconPoint.Y, FLinearColor::Red);
DrawLine(secconPoint.X, firstPoint.Y, secconPoint.X, secconPoint.Y, FLinearColor::Red);
DrawLine(firstPoint.X, secconPoint.Y, secconPoint.X, secconPoint.Y, FLinearColor::Red);
secconPoint -= firstPoint;
//TODO
if (GetActorsInSelectionRectangle<APawn*>(&firstPoint, &secconPoint, &foundActors, true, false))
{
}
}
}
}
}