562{
564 SCOPE_CYCLE_COUNTER(STATGROUP_BaseHelpers_BPLib);
565 const ECollisionChannel CollisionChannel = UEngineTypes::ConvertToCollisionChannel(TraceChannel);
566 const float DrawDebugColorDarkMultiplier = 0.1f;
567 const float DrawDebugColorLightMultiplier = 2.0f;
568 FCollisionQueryParams Params;
569 Params.bDebugQuery = bDebug;
570 Params.bTraceComplex = bTraceComplex;
571 Params.bReturnPhysicalMaterial = bReturnPhysicalMaterial;
572 if (bIgnoreSelf)
573 {
574 const AActor* IgnoreActor = Cast<AActor>(WorldContextObject);
575 if (IgnoreActor)
576 {
577 Params.AddIgnoredActor(IgnoreActor);
578 }
579 else
580 {
581
582 const UObject* CurrentObject = WorldContextObject;
583 while (CurrentObject)
584 {
585 CurrentObject = CurrentObject->GetOuter();
586 IgnoreActor = Cast<AActor>(CurrentObject);
587 if (IgnoreActor)
588 {
589 Params.AddIgnoredActor(IgnoreActor);
590 break;
591 }
592 }
593 }
594 }
595 Params.AddIgnoredActors(ActorsToIgnore);
596
597 UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
598 bool const bHit = World ? World->LineTraceSingleByChannel(
Hit, Start, End, CollisionChannel, Params) :
false;
599
601 {
602 const bool bPersistent =
GetDrawDebugType(bDebug) == EDrawDebugTrace::Persistent;
603 const float LifeTime = (
GetDrawDebugType(bDebug) == EDrawDebugTrace::ForDuration) ? DrawTime : 0.f;
604
605 if (bHit &&
Hit.bBlockingHit)
606 {
607 const FLinearColor DarkerColor = FLinearColor(TraceColor.R * DrawDebugColorDarkMultiplier, TraceColor.G * DrawDebugColorDarkMultiplier, TraceColor.B * DrawDebugColorDarkMultiplier, TraceColor.A);
608 const FLinearColor LighterColor = FLinearColor((TraceColor.R + 0.1f) * DrawDebugColorLightMultiplier, (TraceColor.G + 0.1f) * DrawDebugColorLightMultiplier, (TraceColor.B + 0.1f) * DrawDebugColorLightMultiplier, TraceColor.A);
609
610 DrawDebugLine(World, Start,
Hit.ImpactPoint, TraceColor.ToFColor(
true), bPersistent, LifeTime);
611 DrawDebugLine(World,
Hit.ImpactPoint, End, LighterColor.ToFColor(
true), bPersistent, LifeTime);
612 DrawDebugPoint(World,
Hit.ImpactPoint, 16.0f, DarkerColor.ToFColor(
true), bPersistent, LifeTime);
613 }
614 else
615 {
616
617 DrawDebugLine(World, Start, End, TraceColor.ToFColor(true), bPersistent, LifeTime);
618 }
619 }
620
621 return bHit;
622}
static bool LineTraceByChannel(const UObject *WorldContextObject, FHitResult &Hit, const FVector &Start, const FVector &End, const ETraceTypeQuery TraceChannel, const TArray< AActor * > &ActorsToIgnore, const bool bIgnoreSelf, const bool bReturnPhysicalMaterial=false, const bool bTraceComplex=false, const bool bDebug=false, const FLinearColor TraceColor=FLinearColor::Red, const float DrawTime=2.0f)
Definition BaseHelpersBPLib.cpp:558