UKismetSystemLibrary::LineTraceSingleForObjects
#include "Kismet/KismetSystemLibrary.h"
Access: public
Specifiers: staticBlueprintCallable
Description
Traces a line from Start to End and returns the first hit against any component whose collision is set to respond to one of the given Object Types. Exposed to Blueprint as 'Line Trace For Objects'.
Caveats & Gotchas
- • ObjectTypes filters by UE's Object Type classification (WorldStatic, WorldDynamic, Pawn, Vehicle, Destructible, PhysicsBody, plus custom types), which is entirely separate from Trace Channels — a component's per-channel collision responses don't affect whether it's found here, only its 'Object Type' setting in the collision profile does.
- • Because this queries by Object Type rather than channel, there's no concept of a blocking response overriding an overlap response — any component with a matching Object Type registers as a hit.
- • ActorsToIgnore is still respected even though the filtering model is different from the by-channel traces.
Signature
static ENGINE_API bool LineTraceSingleForObjects(const UObject* WorldContextObject, const FVector Start, const FVector End, const TArray<TEnumAsByte<EObjectTypeQuery> > & ObjectTypes, bool bTraceComplex, const TArray<AActor*>& ActorsToIgnore, EDrawDebugTrace::Type DrawDebugType, FHitResult& OutHit, bool bIgnoreSelf, FLinearColor TraceColor = FLinearColor::Red, FLinearColor TraceHitColor = FLinearColor::Green, float DrawTime = 5.0f ) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| WorldContextObject | const UObject* | World context. | — |
| Start | const FVector | Start of the line segment. | — |
| End | const FVector | End of the line segment. | — |
| ObjectTypes | const TArray<TEnumAsByte<EObjectTypeQuery>>& | Array of Object Types to trace against. | — |
| bTraceComplex | bool | True to test against complex collision, false to test against simplified collision. | — |
| ActorsToIgnore | const TArray<AActor*>& | Actors to exclude from the trace. | — |
| DrawDebugType | EDrawDebugTrace::Type | Debug draw mode. | — |
| OutHit | FHitResult& | Properties of the trace hit. | — |
| bIgnoreSelf | bool | Whether to ignore the world context actor itself. | — |
| TraceColor | FLinearColor | Debug draw color for the trace. | FLinearColor::Red |
| TraceHitColor | FLinearColor | Debug draw color for hits. | FLinearColor::Green |
| DrawTime | float | How long the debug draw persists, in seconds. | 5.0f |
Return Type
bool Example
Line trace against dynamic world objects only C++
FHitResult Hit;
TArray<TEnumAsByte<EObjectTypeQuery>> ObjectTypes;
ObjectTypes.Add(UEngineTypes::ConvertToObjectType(ECC_WorldDynamic));
TArray<AActor*> ActorsToIgnore;
ActorsToIgnore.Add(this);
const FVector Start = GetActorLocation();
const FVector End = Start + GetActorForwardVector() * 1000.f;
bool bHit = UKismetSystemLibrary::LineTraceSingleForObjects(this, Start, End, ObjectTypes, false, ActorsToIgnore, EDrawDebugTrace::ForDuration, Hit, true); See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?