FCollisionShape StructureCollision = StructureMesh->GetCollisionShape();
FHitResult Hit;
FVector CollisionLocation;
CollisionLocation = GetActorLocation();
CollisionLocation.Z += StructureCollision.GetBox().Z;
bool bHasHit = GetWorld()->SweepSingleByChannel(Hit, CollisionLocation, CollisionLocation, FQuat::Identity, ECollisionChannel::ECC_GameTraceChannel2, StructureCollision); //<--
DrawDebugBox(GetWorld(), CollisionLocation, StructureCollision.GetExtent(), (bHasHit ? FColor::Green : FColor::Red), true, 5.f);
What I am expecting: When StructureMesh (Static Mesh) is overlapping with another actor in the scene that respons to the appropriate channel (and this code is called) the debug box should be green.
What happens instead: The debug box does not turn green and therefore no hit results are generated.
But replacing
bool bHasHit = GetWorld()->SweepSingleByChannel(Hit, CollisionLocation, CollisionLocation, FQuat::Identity, ECollisionChannel::ECC_GameTraceChannel2, StructureCollision);
with
bool bHasHit = GetWorld()->SweepSingleByChannel(Hit, CollisionLocation, CollisionLocation, FQuat::Identity, ECollisionChannel::ECC_GameTraceChannel2, FCollisionShape::MakeSphere(300.f));
does lead to the debug color turning green.
Note: Using FCollisionShape::MakeBox(300.f, 300.f, 300.f) doesn’t work either.
How can I fix this?