Using FCollisionObjectQueryParams

I’m trying to create a simple linecast that returns any hits for the custom object type of “Track”

I’m very confused by the documentation and have been unable to find an example. How exactly do I find a the Object Channel Track?

Psudo Code

if(GetWorld()->LineTraceSingleByObjectType(HitResult, startPos, endPos, const FCollisionObjectQueryParams("Track")))
//I'm over a track!

Thanks for any help.

1 Like


So I sort of figured it out but am still having some issues:

DrawDebugLine(GetWorld(), startPos, endPos, FColor(255, 0, 0), false, .1f, 0, 12.3f);
if (GetWorld()->LineTraceSingleByObjectType(HitResult, startPos, endPos, FCollisionObjectQueryParams(EObjectTypeQuery::ObjectTypeQuery1)))
//do stuff if you found an object.

The above code works but the line trace seems to collide with everything. I tried changing ObjectTypeQuery1 to ObjectTypeQuery7 as my custom “Track” object type is the 7th in the editor list, but the line trace then does not collide with anything. (apparently that’s how it works according to someone’s trial and error tests…

As you see from the setup the linetrace debug and “track object” object type or indicated by the blue arrows.

The desired functionality is that the line trace only collides and returns true when it hits an object of type “track”. I can tell its going through the track (the debug line is) but it does not return a collision when object type is set to ObjectTypeQuery7.

What am I doing wrong here?

This is the solution. I needed to convert the enum to a Byte:

TEnumAsByte<EObjectTypeQuery> ObjectToTrace = EObjectTypeQuery::ObjectTypeQuery7;
TArray<TEnumAsByte<EObjectTypeQuery> > ObjectsToTraceAsByte;

if (GetWorld()->LineTraceSingleByObjectType(HitResult, startPos, endPos, FCollisionObjectQueryParams(ObjectsToTraceAsByte))

I know this is an old thread, but there is a helper function that makes this a little clearer. If you include “Runtime/Engine/Classes/Engine/EngineTypes.h” you can use UEngineTypes::ConvertToObjectType to convert a collision channel to an object type.

TArray<TEnumAsByte<EObjectTypeQuery>> TraceObjectTypes;


World->LineTraceSingleByObjectType(Hit, StartPos, EndPos, TraceObjectTypes)


you’re both my heroes right now :stuck_out_tongue: