{ }Blueprint → C++

Unreal Engine 5 · Blueprint → C++

Sphere Trace By Channel in Unreal Engine 5 C++UE Docs

Sphere Trace By Channel becomes UKismetSystemLibrary::SphereTraceSingle() in C++, which sweeps a sphere of a given radius along a trace channel and returns the first blocking hit in an FHitResult.

Blueprint node & C++ equivalent

C++
#include "Kismet/KismetSystemLibrary.h"

FHitResult Hit;
bool bHit = UKismetSystemLibrary::SphereTraceSingle(
  this, Start, End, /*Radius=*/50.f,
  UEngineTypes::ConvertToTraceType(ECC_Visibility), false, {},
  EDrawDebugTrace::ForDuration, Hit, true);

What does Sphere Trace By Channel do?

It sweeps a sphere from a start point to an end point along a collision trace channel and reports the first object that blocks that channel. Unlike a line trace, the sphere has volume, so it detects geometry the thin line would miss, which is useful for lenient aim assist or overlap-style probes.

The C++ equivalent

Include Kismet/KismetSystemLibrary.h and call UKismetSystemLibrary::SphereTraceSingle(). Pass the world context (this), Start and End vectors, the sphere radius, the trace channel, a complex-trace flag, an actors-to-ignore array, a draw debug mode, the output FHitResult, and whether to ignore self.

The trace channel is supplied with UEngineTypes::ConvertToTraceType(ECC_Visibility), which converts a collision channel into the ETraceTypeQuery the function expects. The function returns a bool that is true when a blocking hit occurred.

How to read the result

Check the returned bool before using Hit. When true, Hit.GetActor(), Hit.ImpactPoint, and Hit.ImpactNormal describe the struck object. Passing EDrawDebugTrace::ForDuration draws the swept sphere so you can visualize the cast while tuning the radius.

Frequently asked questions

What is the C++ function for Sphere Trace By Channel in UE5?+

UKismetSystemLibrary::SphereTraceSingle() from Kismet/KismetSystemLibrary.h is the direct equivalent of the Sphere Trace By Channel Blueprint node.

How do I pass a trace channel to SphereTraceSingle?+

Convert a collision channel with UEngineTypes::ConvertToTraceType(ECC_Visibility) and pass the resulting ETraceTypeQuery value as the channel argument.

What is the difference between a sphere trace and a line trace?+

A sphere trace sweeps a sphere of a set radius and so has volume, while a line trace is an infinitely thin ray; the sphere catches objects the line would pass beside.

Related Utilities nodes

View all Utilities nodes →