# How can I get a particle to spawn in a specific location?

**URL:** <https://forums.unrealengine.com/t/how-can-i-get-a-particle-to-spawn-in-a-specific-location/281941>\
**Category:** FX\
**Tags:** world, spawn, fvector, unreal-engine, particle, question, CPP\
**Created:** [April 28, 2014, 8:07pm UTC](https://forums.unrealengine.com/t/how-can-i-get-a-particle-to-spawn-in-a-specific-location/281941 "2014-04-28T20:07:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_44db827a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_44db827a](https://forums.unrealengine.com/u/anonymous_user_44db827a)\
**Post date:** [April 28, 2014, 8:07pm UTC](https://forums.unrealengine.com/t/how-can-i-get-a-particle-to-spawn-in-a-specific-location/281941/1 "2014-04-28T20:07:38Z")

</div>

Hey! I am trying to get some barrel smoke into my game. What I have done is I am trying to spawn a particle at the same location where the projectile spawns. The problem is that for some reason, the particle seems to spawn in the middle of the level (always, it never changes spawn location). Anyone know why this could happen? The code worked perfectly earlier on when I was testing it. Highly appreciate any useful answers or input!

```
const FRotator SpawnRotation = GetControlRotation();
		// MuzzleOffset is in camera space, so transform it to world space before offsetting from the character location to find the final muzzle position
		const FVector SpawnLocation = GetActorLocation() + SpawnRotation.RotateVector(GunOffset);

		UWorld* const World = GetWorld();
		if (World != NULL)
			{
				wpAmmo--;
				FString debugAmmo = FString::FromInt(wpAmmo);
				if (SmokeClass != NULL)
					{
					World->SpawnActor<AOneShotParticle>(SmokeClass, SpawnLocation, SpawnRotation);
					}
				// spawn the projectile at the muzzle
				World->SpawnActor<AInstinctProjectile>(ProjectileClass, SpawnLocation, SpawnRotation);
				GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, debugAmmo);
			}

```

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [April 28, 2014, 8:26pm UTC](https://forums.unrealengine.com/t/how-can-i-get-a-particle-to-spawn-in-a-specific-location/281941/2 "2014-04-28T20:26:58Z")

</div>

#Spawn Emitter Attached

Using an actor for a particle is inefficient and will cost you later down the line

Also, your code wont keep the particle attached if the muzzle moves while the particle is still playing, so it wont look quite right 🙂

**use this instead!**

```
UGameplayStatics::SpawnEmitterAttached(
	ThePSC, //UParticleSystem*
	SkelMeshToAttachTo, 
	SocketName, 
	FVector(0,0,0), //relative offset 
	FRotator(0,0,0), //relative rotation
	EAttachLocation::KeepRelativeOffset, 
	true //auto delete on completion
);

```

🙂

Rama

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_44db827a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_44db827a](https://forums.unrealengine.com/u/anonymous_user_44db827a)\
**Post date:** [April 29, 2014, 2:29pm UTC](https://forums.unrealengine.com/t/how-can-i-get-a-particle-to-spawn-in-a-specific-location/281941/3 "2014-04-29T14:29:48Z")

</div>

Thank you for your answer! My Unreal Engine is experiencing some crashes and I don’t know why, but I will look into this once I get it fixed.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_44db827a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_44db827a](https://forums.unrealengine.com/u/anonymous_user_44db827a)\
**Post date:** [April 30, 2014, 5:47pm UTC](https://forums.unrealengine.com/t/how-can-i-get-a-particle-to-spawn-in-a-specific-location/281941/4 "2014-04-30T17:47:05Z")

</div>

Sorry, but I had a small question regarding the SpawnEmitter. It works very well, but how can I deactivate it? I only wanted it to spawn particles for a second or so at a time. Would really appreciated a reply!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4b90fa9e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4b90fa9e](https://forums.unrealengine.com/u/anonymous_user_4b90fa9e)\
**Post date:** [December 31, 2014, 6:51am UTC](https://forums.unrealengine.com/t/how-can-i-get-a-particle-to-spawn-in-a-specific-location/281941/5 "2014-12-31T06:51:01Z")

</div>

Not sure if you ever figured this out but I think the particle system itself can have a lifetime , and then setting that last value to true should destroy it.
