Quick answer: Build Start and End in world space (GetComponentLocation + GetForwardVector * Distance). Pass an FCollisionQueryParams with AddIgnoredActor(GetOwner()). Verify the trace channel response on potential targets.
Player’s muzzle component runs LineTraceByChannel forward. Bullets pass through enemies. Trace starts inside the player’s capsule and self-ignores; geometry beyond is missed.
The Symptom
OutHit is empty even when geometry visibly sits in front of the trace path.
The Fix
UMuzzleComponent* Muzzle = ...;
FVector Start = Muzzle->GetComponentLocation();
FVector End = Start + Muzzle->GetForwardVector() * 5000.0f;
FCollisionQueryParams Params;
Params.AddIgnoredActor(GetOwner());
Params.bTraceComplex = false;
FHitResult Hit;
bool bHit = GetWorld()->LineTraceSingleByChannel(
Hit, Start, End, ECC_Weapon, Params);
DrawDebugLine(GetWorld(), Start, End, bHit ? FColor::Red : FColor::Green, false, 0.1f);
if (bHit) UE_LOG(LogTemp, Log, TEXT("Hit %s"), *Hit.GetActor()->GetName());
World-space coords. Self-actor ignored. Debug line shows the trace; red = hit, green = miss.
Trace Channel
ECC_Weapon (or your custom channel) must be configured per target as Block. Wall has Weapon = Block. Enemy capsule has Weapon = Block. See related post for collision channels.
Verifying
Run with DrawDebugLine. Confirm visually the trace starts at the muzzle and ends where you expected. Hit = red where geometry is.
“World coords. Ignore self. Right channel response. Hit lands.”
Related Issues
For collision channel response, see trace response. For Replication Graph, see replication.
World space. Ignore self. Hits land.