How To Initialize PrimitiveComponent::LineTraceComponent Correctly?

Dear Friends at Epic,

I can correctly do a PrimitiveComponent::K2_LineTraceComponent,

but I cannot figure out how to do the PrimitiveComponent::LineTraceComponent myself

With the exact same inputs as seen below, I can only get the K2 version to return when a component trace succeeds.

The regular PrimitiveComponent::LineTraceComponent version never finds a hit, ever, in the exact same game situations.

#The K2 Version

Mesh->K2_LineTraceComponent(
	CombatTraces.Traces[0].Start, 
	CombatTraces.Traces[0].End,  
	true, 
	false, 
	CombatHit.ImpactPoint, 
	CombatHit.ImpactNormal
);


if(CombatHit.ImpactPoint != FVector::ZeroVector) 
{
	CombatDamageHit = true;
	DrawDebugLine(
		GetWorld(), 
		CombatTraces.Traces[0].Start, 
		CombatTraces.Traces[0].End,  
		FColor(0,255,255), 
		false, 2, 0, 
		7.f
	);
}

#The Regular PrimitiveComponent::LineTraceComponent

/*
CombatCollisionQuery = FCollisionQueryParams(FName(TEXT("CombatTrace")), true, NULL);
CombatCollisionQuery.bTraceComplex 		= true;
CombatCollisionQuery.bTraceAsyncScene 		= true;
CombatCollisionQuery.bReturnPhysicalMaterial 	= false;


Mesh->LineTraceComponent( 
	CombatHit, 
	CombatTraces.Traces[0].Start, 
	CombatTraces.Traces[0].End, 
	CombatCollisionQuery
);
if(CombatHit.bBlockingHit) 
{
	CombatDamageHit = true;
	DrawDebugLine(
		GetWorld(), 
		CombatTraces.Traces[0].Start, 
		CombatTraces.Traces[0].End,  
		FColor(0,255,255), 
		false, 2, 0, 
		7.f
	);
}
*/

#CollisionQueryParams

I set the ignore actor to NULL because I dont want any actors ignored, and this function is being run within the actor whose mesh is being checked so I cant use “this”

#What Am I Missing?

What am I missing so that I can do the LineTraceComponent myself and not use the K2 version?

#Thanks!

Thanks!

:slight_smile:

Rama

Hi Rama,

Try setting bTraceAsyncScene to false. The “async” physics scene is a secondary physics world that can be used to simulate low-priority objects more efficiently. I.e. cosmetic things that have no effect on the gameplay, such as debris in the street.

I expect most of your colliding objects are not in the async physics scene, as it’s not the default.

Jeff

Thanks for the info Jeff!

I changed Async to false, but still I am getting no collision.

Again the only variance is the function I am using as shown in original post, and the k2 is always working :slight_smile:

//~~~ Combat Collision Query  ~~~
	CombatCollisionQuery = FCollisionQueryParams(FName(TEXT("CombatTrace")), true, NULL); //trace complex, ignore nothing
CombatCollisionQuery.bTraceComplex 				= true;
CombatCollisionQuery.bTraceAsyncScene 			= false;
CombatCollisionQuery.bReturnPhysicalMaterial 	= false;

LineTraceComponent() returns a bool for any hit, blocking or nonblocking. K2_LineTraceComponent will give you a result in both cases.

What is it returning for you? Maybe you are getting a non-blocking hit but your if test is rejecting it.

#Thank You Jeff :heart:

Woohoo that did it!

Here’s my revised code for future reference

if(Mesh->LineTraceComponent( 
	CombatHit, 
	CombatTraces.Traces[0].Start, 
	CombatTraces.Traces[0].End, 
	CombatCollisionQuery)
) {
	CombatDamageHit = true;
	DrawDebugLine(
		GetWorld(), 
		CombatTraces.Traces[0].Start, 
		CombatTraces.Traces[0].End,  
		FColor(0,255,255), 
		false, 2, 0, 
		7.f
	);
}

#Summary

I expected the FHitResult passed into LineTraceComponent to fill bBlockingHit for any type of hit (blocking or nonblocking), an erroneous assumption.

Instead I should rely on the return value of LineTraceComponent to tell me if any kind of hit occurred

#Thanks Again!

:slight_smile:

Rama