{ }Blueprint → C++

Unreal Engine 5 · Blueprint → C++

Line Trace For Objects in Unreal Engine 5 C++UE Docs

Line Trace For Objects maps to GetWorld()->LineTraceSingleByObjectType() in C++, which traces against object types listed in an FCollisionObjectQueryParams rather than a trace channel.

Blueprint node & C++ equivalent

C++
FHitResult Hit;
FCollisionObjectQueryParams ObjParams;
ObjParams.AddObjectTypesToQuery(ECC_Pawn);
bool bHit = GetWorld()->LineTraceSingleByObjectType(Hit, Start, End, ObjParams);

What does Line Trace For Objects do?

Instead of querying a single trace channel, this node tests a ray against a set of collision object types, such as Pawn, WorldStatic, or PhysicsBody. It returns the first object whose type is in the query set, making it ideal when you care about what kind of object you hit rather than a generic visibility line.

The C++ equivalent

Build an FCollisionObjectQueryParams and call AddObjectTypesToQuery() for each object type you want, for example ECC_Pawn. Then call GetWorld()->LineTraceSingleByObjectType(Hit, Start, End, ObjParams), passing your FHitResult and the start and end points.

The function returns a bool that is true on a hit. Because it goes through GetWorld(), the calling object must have a valid UWorld, so call it from an actor or component during gameplay.

When to use object-type traces

Reach for LineTraceSingleByObjectType when you need to filter by object category, such as only detecting pawns for an interaction prompt. To collect every object along the ray instead of just the first, use LineTraceMultiByObjectType with a TArray<FHitResult>.

Frequently asked questions

What is the C++ equivalent of Line Trace For Objects in UE5?+

Use GetWorld()->LineTraceSingleByObjectType(Hit, Start, End, ObjParams) with an FCollisionObjectQueryParams describing the object types to test.

How do I add object types to a trace in C++?+

Create an FCollisionObjectQueryParams and call AddObjectTypesToQuery(ECC_Pawn) (or another collision channel) for each object category you want to include.

What is the difference from LineTraceSingleByChannel?+

ByChannel tests against one trace channel's response, while ByObjectType tests against a set of object types so you can match specific object categories.

Related Utilities nodes

View all Utilities nodes →