Developer Notes

This is by design, the query system is confusing which is why we've introduced explicit functions instead of these crazy overloaded signature ones.

Description

The collision channel specified in LineTraceSingleByChannel does not appear to be taken into account when the trace is performed. Instead of ignoring any objects that are not set to that channel, any object that is hit is returned.

The same behavior is observed in the current LineTraceSingle() function that is set to be deprecated in 4.8.

Steps to Reproduce
  1. Create a new code project using the First Person template, no starter content.
  2. In the Character .cpp file created for the project, replace the contents of the OnFire() function with the following code:
    	FVector CamLoc;
    	FRotator CamRot;
    	this->GetController()->GetPlayerViewPoint(CamLoc, CamRot);
    	const FVector TraceDirection = CamRot.Vector();
    
    	FVector StartTrace = FVector::ZeroVector;
    	FRotator UnusedRotation;
    	this->GetController()->GetPlayerViewPoint(StartTrace, UnusedRotation);
    
    	StartTrace = StartTrace + TraceDirection*((GetActorLocation() - StartTrace) | TraceDirection);
    
    	const float TraceRange = 4096.f;
    	const FVector EndTrace = StartTrace + TraceDirection * TraceRange;
    
    	static FName TraceIdent = FName(TEXT("TheTrace"));
    	FCollisionQueryParams TraceParams(TraceIdent, true, this);
    
    	FHitResult TheHitResult;
    
    	GetWorld()->LineTraceSingleByChannel(TheHitResult, StartTrace, EndTrace, ECC_WorldStatic, TraceParams);
    
  3. Build the project in Visual Studio.
  4. Open the project in the Editor.
  5. Create a new level.
  6. Add several static mesh objects to the level and set them to different collision channels.
  7. Start PIE mode.
  8. Fire the line trace at each static mesh object in the level.

RESULTS:
The hit result registers a hit for any line trace that hits a static mesh in the level, regardless of the collision channel that static mesh is set to.

EXPECTED:
The hit result registers a hit only for line traces that hit a static mesh with the collision channel set to ECC_WorldStatic.

Have Comments or More Details?

Head over to the existing Questions & Answers thread and let us know what's up.

0
Login to Vote

By Design
ComponentUE - Simulation - Physics
Affects Versions4.7.64.9
CreatedMay 5, 2015
ResolvedMay 6, 2015
UpdatedJul 14, 2021
View Jira Issue