# Spawning an explosion effect without using a blueprint?

**URL:** <https://forums.unrealengine.com/t/spawning-an-explosion-effect-without-using-a-blueprint/20426>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [February 6, 2015, 5:23am UTC](https://forums.unrealengine.com/t/spawning-an-explosion-effect-without-using-a-blueprint/20426 "2015-02-06T05:23:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Whammy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Whammy](https://forums.unrealengine.com/u/Whammy)\
**Post date:** [February 6, 2015, 5:23am UTC](https://forums.unrealengine.com/t/spawning-an-explosion-effect-without-using-a-blueprint/20426/1 "2015-02-06T05:23:57Z")

</div>

I’m having trouble finding examples of how to spawn an explosion effect using pure c++ without the aid of a blueprint. I want to play the P\_Explosion effect at an impact point. I have the coordinates, but I can’t figure out how to play the particle effect there.

---

<div class="post-metadata">

**Author:** ![anon26705860](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anon26705860](https://forums.unrealengine.com/u/anon26705860)\
**Post date:** [February 6, 2015, 6:48pm UTC](https://forums.unrealengine.com/t/spawning-an-explosion-effect-without-using-a-blueprint/20426/2 "2015-02-06T18:48:33Z")

</div>

```auto

FHitResult Hit;
FVector SpawnLocation = Hit.ImpactPoint;
FRotator SpawnRotation = Hit.ImpactNormal.Rotation();
UParticleSystem* EmitterTemplate = your ref to P_Explosion
UGameplayStatics::SpawnEmitterAtLocation(WorldContextObject, EmitterTemplate, SpawnLocation, SpawnRotation);

```

---

<div class="post-metadata">

**Author:** ![Whammy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Whammy](https://forums.unrealengine.com/u/Whammy)\
**Post date:** [February 6, 2015, 8:17pm UTC](https://forums.unrealengine.com/t/spawning-an-explosion-effect-without-using-a-blueprint/20426/3 "2015-02-06T20:17:41Z")

</div>

I tried that. However, there’s the issue of getting a reference to the template. It seems that you need a blueprint in order to get the template.

---

<div class="post-metadata">

**Author:** ![anon26705860](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anon26705860](https://forums.unrealengine.com/u/anon26705860)\
**Post date:** [February 6, 2015, 8:49pm UTC](https://forums.unrealengine.com/t/spawning-an-explosion-effect-without-using-a-blueprint/20426/4 "2015-02-06T20:49:20Z")

</div>

You should use static ConstructorHelpers::FObjectFinder to find the reference to the asset if you don’t want to expose the system and set it in blueprint.

---

<div class="post-metadata">

**Author:** ![Vrtual](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/vrtual/32/1025445_2.png) [@Vrtual](https://forums.unrealengine.com/u/Vrtual)\
**Post date:** [March 28, 2016, 9:45am UTC](https://forums.unrealengine.com/t/spawning-an-explosion-effect-without-using-a-blueprint/20426/5 "2016-03-28T09:45:09Z")

</div>

and how do you get a callback to destroy the actor after the explosion is finished? you don’t want to leave this garbage there do you?

---

<div class="post-metadata">

**Author:** ![Jambax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jambax/32/904177_2.png) [@Jambax](https://forums.unrealengine.com/u/Jambax)\
**Post date:** [March 28, 2016, 9:55am UTC](https://forums.unrealengine.com/t/spawning-an-explosion-effect-without-using-a-blueprint/20426/6 "2016-03-28T09:55:50Z")

</div>

Yeah, you still need to tell it what template to use. You either hardcode it using FObjectFinder or StaticLoadObject (and thus have a C++ class for every different explosion you want to make) - or you use a Blueprinted version of your explosion class and set the defaults there.  
@nullbot - You can tell Emitters to auto-destroy themselves when they finish.

---

<div class="post-metadata">

**Author:** ![wilc4rd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@wilc4rd](https://forums.unrealengine.com/u/wilc4rd)\
**Post date:** [March 28, 2016, 10:09am UTC](https://forums.unrealengine.com/t/spawning-an-explosion-effect-without-using-a-blueprint/20426/7 "2016-03-28T10:09:28Z")

</div>

make sure it loops once and destroy on finish are on 😃

---

<div class="post-metadata">

**Author:** ![MPalacios](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MPalacios](https://forums.unrealengine.com/u/MPalacios)\
**Post date:** [March 28, 2016, 10:28am UTC](https://forums.unrealengine.com/t/spawning-an-explosion-effect-without-using-a-blueprint/20426/8 "2016-03-28T10:28:05Z")

</div>

> [@TheJamsh;501170](#):
>
> Yeah, you still need to tell it what template to use. You either hardcode it using FObjectFinder or StaticLoadObject (and thus have a C++ class for every different explosion you want to make) - or you use a Blueprinted version of your explosion class and set the defaults there.  
> @nullbot - You can tell Emitters to auto-destroy themselves when they finish.

C++ class for every different explosion?  
I did it this way;

in .h

```auto

USTRUCT(BlueprintType)
struct WHATEVS_API FParticleEffects {
	GENERATED_USTRUCT_BODY()
public:
	FParticleEffects {}

	TArray<UParticleSystem*> aExplosions;

};
extern FParticleEffects ParticleEffects;

```

in .cpp

```auto

FParticleEffects ParticleEffects;

AMyClass::AMyClass(const FObjectInitializer& ObjectInitializer) {
ConstructorHelpers::FObjectFinder<UParticleSystem> PEffectQuery = TEXT("ParticleSystem'/Game/Art/ParticleEffects/SomeExplosion1'");
	ParticleEffects.aExplosions.Add(PEffectQuery.Object);
	
PEffectQuery = (TEXT("ParticleSystem'/Game/Art/ParticleEffects/SomeExplosion2'"));
	ParticleEffects.aExplosions.Add(PEffectQuery.Object);

PEffectQuery = (TEXT("ParticleSystem'/Game/Art/ParticleEffects/SomeExplosion3'"));
	ParticleEffects.aExplosions.Add(PEffectQuery.Object);

.
.
.

PEffectQuery = (TEXT("ParticleSystem'/Game/Art/ParticleEffects/SomeExplosionN'"));
	ParticleEffects.aExplosions.Add(PEffectQuery.Object);

}

```

This way your struct which holds all your particle effects is available to all classes which include your .h-file via the extern keyword.

UStructs can also hold functions if you’d like to for example get a random explosion emitter.

---

<div class="post-metadata">

**Author:** ![Jambax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jambax/32/904177_2.png) [@Jambax](https://forums.unrealengine.com/u/Jambax)\
**Post date:** [March 28, 2016, 3:51pm UTC](https://forums.unrealengine.com/t/spawning-an-explosion-effect-without-using-a-blueprint/20426/9 "2016-03-28T15:51:21Z")

</div>

Interesting, different strokes I guess. I personally prefer to just abstract the class with a Blueprint and set the defaults.
