# Exception thrown at spawning particles

**URL:** <https://forums.unrealengine.com/t/exception-thrown-at-spawning-particles/466950>\
**Category:** FX\
**Tags:** error, exception, unreal-engine, CPP, question\
**Created:** [June 19, 2020, 1:44am UTC](https://forums.unrealengine.com/t/exception-thrown-at-spawning-particles/466950 "2020-06-19T01:44:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![osmeldu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@osmeldu](https://forums.unrealengine.com/u/osmeldu)\
**Post date:** [June 19, 2020, 1:44am UTC](https://forums.unrealengine.com/t/exception-thrown-at-spawning-particles/466950/1 "2020-06-19T01:44:38Z")

</div>

Hello. Im getting an Exception while trying to spawn some particles after I hit an object. This is the code:

header file:

```
UPROPERTY(EditDefaultsOnly, Category = "Explosion")
		UParticleSystem* KilledEnemyParticle;

```

cpp file:

```
void ABulletProjectile::OnHit(UPrimitiveComponent * HitComp, AActor * OtherActor, UPrimitiveComponent * OtherComp, FVector NormalImpulse, const FHitResult & Hit)
{
	if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL))// && (OtherComp->IsSimulatingPhysics())))
	{
		OtherComp->AddImpulseAtLocation(GetVelocity() * 50.0f, GetActorLocation());
		UGameplayStatics::SpawnEmitterAtLocation(this, BulletHitParticle, GetActorLocation());

		if (OtherActor->ActorHasTag(TEXT("Destroyable")))
		{
			
			AActor* ActorToDestroy = OtherActor;

			FTimerHandle TimerHandle;
			FTimerDelegate TimerDelegate;
			
			AZombieRatPawn* ZombieRat = Cast<AZombieRatPawn>(ActorToDestroy);
			
			if (OtherActor != this)
			{
				if (ZombieRat != nullptr)
			{
				TimerDelegate.BindLambda([ActorToDestroy, this, ZombieRat]()
				{
					if (ZombieRat->CanEmmit)
					{
						UGameplayStatics::SpawnEmitterAtLocation(this, KilledEnemyParticle, ActorToDestroy->GetActorLocation());
						ZombieRat->CanEmmit = false;
					}
					ActorToDestroy->Destroy();
				});
				GetWorld()->GetTimerManager().SetTimer(TimerHandle, TimerDelegate, 1.f, false);
			}
			}
			
						
		}
		
	}

	Destroy();

}

```

Im getting this error after UE crashes:

Exception thrown at 0x0000000000000000 in UE4Editor.exe: 0xC0000005: Access violation executing location 0x0000000000000000. occurred

and this is the line that is failing:

```
UGameplayStatics::SpawnEmitterAtLocation(this, KilledEnemyParticle, ActorToDestroy->GetActorLocation());

```

any help would be appreciated. Thanks
