Trace Only Identifys Static Mesh

Situation

I’m trying to make a trace that can identify what it is. HOWEVER It only identifies a Static Mesh.

void AWeapon::ProcessInstantHit(const FHitResult& Impact, const FVector& Origin, const FVector& ShootDir, int32 RandomSeed, float ReticleSpread)
{
	if (Impact.bBlockingHit)		//if anything is blocking the trace
	{
		GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Green, TEXT("HIT SOMETHING!!!"));
		DrawDebugLine(this->GetWorld(), Origin, Impact.TraceEnd, FColor::Black, true, 10000.f, 10.f);		//Draws line to impacted hit
		DrawDebugPoint(this->GetWorld(), Impact.TraceEnd, 100.f, FColor::Black, true, 10000.f, 10.f);		//Draws box where the trace has hit
	}
	if (Impact.GetActor())
	{

		AActor *HitActor = Cast<AActor>(Impact.GetActor());
		if (HitActor->IsA(AEnemy::StaticClass()))
		{
			GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Green, TEXT("ENEMY HIT-----------"));
		}
		
	}
	else
	{
		GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Green, TEXT("NOTHING TO HITTTTTTT"));
	}
}

This is the code i have for the trace. Everything works fine absolutely fine, just the trace wont identify ANYTHING unless it’s a Static Mesh.

HELP

Is it a bug that using a trace only identifies Static Meshes? It wont identify My Skeletal mesh at all. Does anyone have a solution to this problem?

Anything at all???

hi,

Can you show us your collision/trace response setup for your skeletal mesh? And parameters passed to trace functions?

Best regards

Pierdek

that is what I have for my collision trace response setup. I tried all of them and i got nothing :confused:

Have you created Physical asset for this skeletal mesh? Is root component(Box1) overlapping skeletal mesh?

Show trace responses for Box1, and piece of code that you are using for tracing.

I’m not sure :/. but here’s the code for all of the instances of Trace

void AWeapon::Instant_Fire()
{

	//Get properties for Line Trace
	const int32 RandomSeed = FMath::Rand();																	//Random number seed
	FRandomStream WeaponRandomStream(RandomSeed);															//Streams Random number with seed
	const float CurrentSpread = WeaponConfig.WeaponSpread;													//Gets weapon spread
	const float SpreadCone = FMath::DegreesToRadians(WeaponConfig.WeaponSpread * 0.5f);						//Spread Math control
	const FVector AimDir = WeaponMesh->GetSocketRotation("Fire_Socket").Vector();							//Get Direction of Muzzle
	const FVector StartTrace = WeaponMesh->GetSocketLocation("Fire_Socket");								//Start of trace
	const FVector ShootDir = WeaponRandomStream.VRandCone(AimDir, SpreadCone, SpreadCone);					//Direction with random spread
	const FVector EndTrace = StartTrace + ShootDir * WeaponConfig.WeaponRange;								//End/Range of trace
	const FHitResult Impact = WeaponTrace(StartTrace, EndTrace);											//Detect what the trace hit

	ProcessInstantHit(Impact, StartTrace, ShootDir, RandomSeed, CurrentSpread);
}

FHitResult AWeapon::WeaponTrace(const FVector& TraceFrom, const FVector& TraceTo) const
{
	static FName WeaponFireTag = FName(TEXT("WeaponTrace"));

	// Perform trace to retrieve hit info
	FCollisionQueryParams TraceParams(WeaponFireTag, true, Instigator);
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = true;
	TraceParams.AddIgnoredActor(this);

	//re-initialize the hit
	FHitResult Hit(ForceInit);

	GetWorld()->LineTraceSingle(Hit, TraceFrom, TraceTo, ECC_Pawn, TraceParams);

	return Hit;
}

void AWeapon::ProcessInstantHit(const FHitResult& Impact, const FVector& Origin, const FVector& ShootDir, int32 RandomSeed, float ReticleSpread)
{
if (Impact.bBlockingHit) //if anything is blocking the trace
{
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Green, TEXT(“HIT SOMETHING!!!”));
DrawDebugLine(this->GetWorld(), Origin, Impact.TraceEnd, FColor::Black, true, 10000.f, 10.f); //Draws line to impacted hit
DrawDebugPoint(this->GetWorld(), Impact.TraceEnd, 100.f, FColor::Black, true, 10000.f, 10.f); //Draws box where the trace has hit
SpawnTrailEffect(Impact.ImpactPoint);
}
if (Impact.GetActor())
{

		AActor *HitActor = Cast<AActor>(Impact.GetActor());
		if (HitActor->IsA(AEnemy::StaticClass()))
		{
			GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Green, TEXT("ENEMY HIT-----------"));
		}
		
	}
	else
	{
		GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Green, TEXT("NOTHING TO HITTTTTTT"));
	}
}

and here’s my collision checks for box

as for the box, it is the root component, however, even when i switch the skeletal to be the root, still nothing happens. but like i said if it’s a static mesh, it works great. even with the box1 being the root component. also keep in mind my character is the built in blue mannequin. i believe it does not have one

[EDIT]
I added a physics Asset to the mannequin, but still nothing for the trace :confused:

Why are you using Object Response type ECC_Pawn for tracing?

You should create a special trace response channel for weapon:

DefaultEngine.ini

+DefaultChannelResponses=(Channel=ECC_GameTraceChannel1, Name="Weapon",DefaultResponse=ECR_Block,bTraceType=True,bStaticObject=False))

Then You can declare macro that mapping your type to engine built-in type:

#define TRACE_WEAPON           ECC_GameTraceChannel1

and use this stuff instead of ECC_Pawn.

Why your trace works against static mesh? I don’t know.

The reason why I’m using ECC_Pawn is because the class I’m deriving AEnemy from is a Pawn. I’ll give the custom trace channel a try tho

You sir made my day :)!!! IT WORKS GREAT!!! THANK YOU BUNCHES!!!

Making a custom channel makes a difference!!

Kudos to the answer to Pierdek