Download

MultiLineTrace with multiple collision tags?

Hi there,

I’m trying to convert some basic blueprint code into C++, but there’s one little thing I can’t figure out.
Here’s the BP section:

&stc=1

and here’s my current code:


void AMainCharacter::Tick(float DeltaTime){
    Super::Tick(DeltaTime);


    ACustomPlayerController* Controller = (ACustomPlayerController*)GetWorld()->GetFirstPlayerController();


    FVector CameraLocation = Controller->PlayerCameraManager->GetCameraLocation();
    FVector CameraEndLocation = (Controller->PlayerCameraManager->GetActorForwardVector() * InteractDistance) + CameraLocation;


    TArray<FHitResult> Hit;


    FCollisionQueryParams TraceParams = FCollisionQueryParams(FName(TEXT("Trace")), true, this);
    TraceParams.bTraceAsyncScene = true;


    bool bHasHit = GetWorld()->LineTraceMulti(Hit, CameraLocation, CameraEndLocation, ECC_WorldDynamic, TraceParams);
    DrawDebugLine(GetWorld(), CameraLocation, CameraEndLocation, FColor(255, 0, 0), false, -1, 0, 12.333);


    if (bHasHit)
    {
        GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Red, "Tracing works");
    }
}

The main problem I’m having is getting the node “Make Array: World Dynamic, World Static”.
I thought you could do ECC_WorldDynamic && ECC_WorldStatic, but that doesn’t seem to work.

Is there a solution to this? Thanks in advance for the answer.

You should be able to just make a standard TArray in code of those object types.

I tried the following:


TArray<ECollisionChannel> Channels;
Channels[0] = ECC_WorldDynamic;
Channels[1] = ECC_WorldStatic;

FCollisionQueryParams TraceParams = FCollisionQueryParams(FName(TEXT("Trace")), true, this);
TraceParams.bTraceAsyncScene = true;

bool bHasHit = GetWorld()->LineTraceMulti(Hit, CameraLocation, CameraEndLocation, Channels, TraceParams);

I get this error:


Error    1    error C2664: 'bool UWorld::LineTraceMulti(TArray<FHitResult,FDefaultAllocator> &,const FVector &,const FVector &,const FCollisionQueryParams &,const FCollisionObjectQueryParams &) const' : argument 4 cannot be converted to 'TArray<ECollisionChannel,FDefaultAllocator>' a 'ECollisionChannel'


Basically, this function does not allow me to feed it an array. It has to be a single variable.

I haven’t quite worked out the relationship yet between object types and trace channels, but anyway I believe you need to call the overload that takes an FCollisionObjectQueryParams, which let’s you specify multiple object types.