Hey, i’m trying to get a trace to be able to hit a box component that has set to not collide with any objects with a “No Physics Collision” custom collision preset that looks like this.

This is the code i have for my line trace. The component that has the tag “Object” is a UBoxComponent that i have in another class.
UWorld* TheWorld = GetWorld();
FHitResult HitResult(ForceInit);
FVector StartFVector = FirstPersonCameraComponent->GetComponentLocation();
FVector EndFVector = StartFVector + (FirstPersonCameraComponent->GetForwardVector() * RayLength);
FCollisionQueryParams TraceParams = FCollisionQueryParams(FName(TEXT("InvestigationTrace")), true, this);
TraceParams.bTraceComplex = false;
TraceParams.bReturnPhysicalMaterial = false;
if (TheWorld->LineTraceSingle(HitResult, StartFVector, EndFVector, ECC_WorldStatic, TraceParams))
{
if (HitResult.Component->ComponentHasTag("Object"))
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, "Hit!");
}
}
Currently i’m not getting so that the trace hits the box component, is there anyone who knows what i’m doing wrong that can help me out?
So i think i have found a way to reach what i want, but i’m still a bit confused and it would be great if someone could explain this to me.
This is the code i’m using for the line trace.
UWorld* TheWorld = GetWorld();
FHitResult HitResult(ForceInit);
FVector StartFVector = FirstPersonCameraComponent->GetComponentLocation();
FVector EndFVector = StartFVector + (FirstPersonCameraComponent->GetForwardVector() * RayLength);
FCollisionQueryParams TraceParams = FCollisionQueryParams(FName(TEXT("InvestigationTrace")), true, this);
TraceParams.bTraceComplex = false;
TraceParams.bReturnPhysicalMaterial = false;
if (TheWorld->LineTraceSingle(HitResult, StartFVector, EndFVector, ECC_WorldDynamic, TraceParams))
{
//GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Green, "Hit!");
if (HitResult.Component->ComponentHasTag("Object"))
{
GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Green, "Hit!");
}
}
And this is the collision preset that i got it working with, (i wanted so the player could walk through the box but the trace would hit it)

This works fine, but what i find confusing is that when i use a custom collision preset with the same parameters i don’t get the same effect.

Anyone know why this is not working in the same way?