Hi.
I’m trying to make a gun fire using line trace.
I binded it to LMB, but whenever I press it, it crashes my engine.
Here’s my 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 = GetActorForwardVector() + 100000000.0f;
if (World)
{
World->LineTraceSingleByChannel(FireHit, StartLocation, EndLocation, ECC_Pawn, FireTraceParams);
ProjectileParticleComponent = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("Projectile Hit Particle Component"));
ProjectileParticleComponent->SetWorldLocation(FireHit.ImpactPoint);
ProjectileParticleComponent->SetTemplate(ProjectileParticleSystem);
ProjectileParticleComponent->ActivateSystem();
delete ProjectileParticleComponent;
}
IMPORTANT EDIT:
I commented out the particle component part, and it works. Can you tell me, how to spawn a particle effect at the impact location of a line trace? I’d like to avoid using another actor.
I can include my crash logs if necessary.
If you know the solution, please answer