Hello.
I made a weapon that fires using Line Trace. It works well, but every time it doesn’t hit anything it crashes my engine.
Here’s my Line Trace code:
FCollisionQueryParams FireTraceParams = FCollisionQueryParams(FName(TEXT("FireTrace")), true, this);
FireTraceParams.bTraceComplex = true;
FireTraceParams.bTraceAsyncScene = true;
FireTraceParams.bReturnPhysicalMaterial = false;
FHitResult FireHit(ForceInit);
UWorld* const World = GetWorld();
FVector StartLocation;
StartLocation = GetActorLocation();
FVector EndLocation;
EndLocation = StartLocation + PlayerCamera->GetForwardVector() * 100000000.0f;
if (World && ShootDelay <= 0.0f)
{
World->LineTraceSingleByChannel(FireHit, StartLocation, EndLocation, ECC_Pawn, FireTraceParams);
UGameplayStatics::SpawnEmitterAtLocation(World, ProjectileParticleSystem, FireHit.Location);
ImpactVector = EndLocation / 10000.0f;
if (FireHit.GetComponent()->IsSimulatingPhysics()) FireHit.GetComponent()->AddImpulseAtLocation(ImpactVector, FireHit.ImpactPoint);
ShootDelay = 30.0f;
/*DrawDebugLine(
GetWorld(),
StartLocation,
FireHit.Location,
FColor(255, 0, 0),
false, -1, 0,
12.333
);*/
}
If you know why, then please answer.