C++ Linetrace?

How can i loop through a USceneComponent bp array in c++ and then do a line trace from that location to x and then find the hit result location for each loop?

Something like this ?

	TArray<USceneComponent*> Components;
	FVector TraceTargetLoc; //Specify trace target location.
	for(const USceneComponent* Comp : Components)
	{
		if(Comp)
		{
			FHitResult OutHit;
			if (GetWorld()->LineTraceSingleByChannel(OutHit, Comp->GetComponentLocation(), TraceTargetLoc, ECC_Visibility))
			{
				//Trace hit
				//OutHit.Location
			}
		} 
	}
2 Likes

I will also need this, thank you Sir for posting this :slightly_smiling_face:

1 Like