sphere trace by channel in c++

As this is the first result on google, i am going to post the code here. Sorry for reposting, had to update the formatting.

FHitResult hitResult;
TArray<AActor*> actorsToIgnore;
FVector start = GetActorLocation();
FVector end = start + UKismetMathLibrary::Multiply_VectorFloat(GetActorForwardVector(), 1000)
auto channel = UEngineTypes::ConvertToTraceType(ECollisionChannel::ECC_Visibility);

auto isHit = UKismetSystemLibrary::SphereTraceSingle(
	this,
	start,
	end,
	50.0f,
    channel,
	false,
	actorsToIgnore,
	EDrawDebugTrace::Type::ForDuration,
	hitResult,
	true
);
1 Like