LineTrace doesn't generate Hit on ragdolled SkeletalMesh

Hey guys,

the LineTrace works just fine as long as the NPC is alive. However, once I kill it and enable physics on the SkeletalMesh the LineTrace seems to fail.

Here’s the trace itself:

AActor* AIMP_Player::GetFocusedActor(float withinDistance)
{
	FHitResult hitResult;

	FVector traceStart = FollowCamera->GetComponentLocation();
	FVector forwardVector = FollowCamera->GetForwardVector();
	FVector traceEnd = traceStart + forwardVector * withinDistance;

	FCollisionQueryParams queryParams;

	// remove player actor from trace result
	queryParams.AddIgnoredActor(this);

	if (GetWorld()->LineTraceSingleByChannel(hitResult, traceStart, traceEnd, ECC_WorldDynamic, queryParams))
	{
		UE_LOG(LogTemp, Warning, TEXT("%s"), *(hitResult.GetComponent()->GetOwner()->GetName()));
		return hitResult.GetActor();
	}

	return nullptr;
}

Here’s the code killing the NPC:

void AIMPEnemyNPC::KillNPC(FVector hitImpulse)
{
	bDead = true;
	
	if (Controller)
	{
		Controller->StopMovement();
		Controller->UnPossess();
	}
	
	GetMesh()->SetSimulatePhysics(true);
	GetMesh()->AddForceToAllBodiesBelow(hitImpulse * GetMesh()->GetBodyInstance()->GetBodyMass() * 600.f);
	GetMesh()->AddImpulseToAllBodiesBelow(hitImpulse * GetMesh()->GetBodyInstance()->GetBodyMass() * 600.f);

	UCapsuleComponent* collComp = GetCapsuleComponent();
	
	if(collComp)
	{
		collComp->SetCollisionProfileName("NoCollision", false);
	}
}

Here’s what I’ve tried already:

https://answers.unrealengine.com/questions/46650/problem-character-mesh-not-generating-hit-events.html
https://answers.unrealengine.com/questions/83846/trace-only-identifys-static-mesh.html

I’m kinda stuck and need some help : /

Strange…
I thought I received an answer, but I can’t see it. Whoever answered me, thanks for pushing me in the right direction!
I was able to solve my problem without any limitations.

This was the problem:

The goal was to be able to focus the ragdolled body laying on the ground. The CapsuleComponent triggered all the hit events for focusing and killing the NPC. After the NPC died I obviously deactivated the capsules collisions inside the code, since it’s not supposed to collide with the player anymore.

What I was looking for, was a way to generate a hit event on either the SkeletalMesh itself or its PhysicsAsset.
What I was missing, was enabling the following option on the SkeletalMesh to use complex collision to generate the hit events:

322769-capture02.jpg

This way the CapsuleComponent is solely responsible for Player collision, while shooting , focusing or other hit events are handled on the collision component of the SkeletalMesh itself. If you don’t need a Physics Simulation on the SkeletalMesh you can also pick the “Query Only” option.

Everything else was already setup correctly.

Thanks again!

1 Like

that was me… lol

sorry, I made an answer but deleted it. On testing my answer I figured it was the wrong solution and didn’t want you to try what I already knew was wrong while I tried something else… then life happens and here I came back to try again and you’ve answered it yourself! fantastic!

Trying to get better at answerhub without giving bad advice that wastes people’s time is hard!

My answer was about collision channels, but I’m glad you came to the right solution :slight_smile:

Yes changing to “Collision Enabled (Query and Physics)” worked in my case as well!