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… https://answers.unrealengine.com/questions/74083/what-is-eobjecttypequery-and-how-to-use-it.html
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.
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.
Solution for newer engine version (5.0.3)
It seems to have gottent much simpler to do.
When making your
FCollisionObjectQueryParams colParamsObject = FCollisionObjectQueryParams();
colParamsObject.AddObjectTypesToQuery(ECC_WorldStatic); // UNREAL set
// simply do this: (count the position of the type in your ProjectSettings. Starts at 1 and not 0 (for programmers)
colParamsObject.AddObjectTypesToQuery(ECC_GameTraceChannel5); // YOURs added
For consistency you may reference and custom name all your custom trace channels in one .h and include it. Ie the ProjectName.h as such:
#define EEC_InivisbleWall_AI ECC_GameTraceChannel5
// and use as:
colParamsObject.AddObjectTypesToQuery(EEC_InivisbleWall_AI);