Line trace question

Hi there community, i made this line tracing for a shooting game, and at this point id like to make the line disapear after certain time(5secs).

I know there is a way to make it, but i cant make it work.

Here is the part of the code , maybe its the way its structured or something im clueless about this right now.

This is in the .cpp part, dont know if its here or somewhere else that i have to change it.

void AWeapon::Instant_Fire()
{
		const int32 RandomSeed = FMath::Rand();
		FRandomStream WeaponRandomStream(RandomSeed);
		const float CurrentSpread = WeaponConfig.WeaponSpread;
		const float SpreadCone = FMath::DegreesToRadians(WeaponConfig.WeaponSpread * 0.5);
		const FVector AimDir = WeaponMesh->GetSocketRotation("MF").Vector();
		const FVector StartTrace = WeaponMesh->GetSocketLocation("MF");
		const FVector ShootDir = WeaponRandomStream.VRandCone(AimDir, SpreadCone, SpreadCone);
		const FVector EndTrace = StartTrace + ShootDir * WeaponConfig.WeaponRange;
		const FHitResult Impact = WeaponTrace(StartTrace, EndTrace);
		 

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

}

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

	FCollisionQueryParams TraceParams(WeaponFireTag, true, Instigator);
	TraceParams.bTraceAsyncScene = true;
	TraceParams.bReturnPhysicalMaterial = true;
	TraceParams.AddIgnoredActor(this);

	FHitResult Hit(ForceInit);

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

	return Hit;
}

void AWeapon::ProcessInstantHit(const FHitResult &Impact, const FVector &Origin, const FVector ShootDir, int32 RandomSeed, float ReticalSpread)
{
	const FVector EndTrace = Origin + ShootDir * WeaponConfig.WeaponRange;
	const FVector EndPoint = Impact.GetActor() ? Impact.ImpactPoint : EndTrace;
	DrawDebugLine(this->GetWorld(), Origin, Impact.TraceEnd, FColor::Black, true, 10000, 10.f);

That’s the ShooterGame Code i guess.

If you mean the DebugLine, then yes, it is at the bottom of your code snippet here.

You will want to change the “true” to “false” since this is for “persistent” and change the 1000 to your lifetime.

ill try it , thanks for the quick reply :slight_smile:

Worked thank you