# How do I reference my particle system in code?

**URL:** <https://forums.unrealengine.com/t/how-do-i-reference-my-particle-system-in-code/337253>\
**Category:** Editor Scripting\
**Tags:** reference, particle-systems, unreal-engine, question, CPP\
**Created:** [November 2, 2015, 8:12pm UTC](https://forums.unrealengine.com/t/how-do-i-reference-my-particle-system-in-code/337253 "2015-11-02T20:12:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![LostScout](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LostScout](https://forums.unrealengine.com/u/LostScout)\
**Post date:** [November 2, 2015, 8:12pm UTC](https://forums.unrealengine.com/t/how-do-i-reference-my-particle-system-in-code/337253/1 "2015-11-02T20:12:16Z")

</div>

In the tutorial for Variables, timers and, events near the end, you are shown how to create a particle emitter via Blueprint. I was curious about how to achieve this through code as opposed to Blueprints. I have checked out the Particle systems documentation but am unsure of how to reference the starter content “P\_Explosion” in my code. Any direction would be much appreciated.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_d4cefbf7](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d4cefbf7](https://forums.unrealengine.com/u/anonymous_user_d4cefbf7)\
**Post date:** [November 3, 2015, 4:49pm UTC](https://forums.unrealengine.com/t/how-do-i-reference-my-particle-system-in-code/337253/2 "2015-11-03T16:49:32Z")

</div>

Hi.

Direct references to assets in C++ code should be avoided. It’s better to declare particle system component in your header file like this:

```
UPROPERTY(VisibleAnywhere)
class UParticleSystemComponent* PSC;

```

Then create it in your constructor:

```
PSC = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("MyPSC"));

```

And then set it’s template in editor.

If you still need a reference to particle system, you can get it like this:

```
static ConstructorHelpers::FObjectFinder<UParticleSystem> PS(TEXT("ParticleSystem'/Game/StarterContent/Particles/P_Explosion.P_Explosion'"));
PSC = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("MyPSC"));
PSC->SetTemplate(PS.Object);

```

Hope this helps.

---

<div class="post-metadata">

**Author:** ![LostScout](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LostScout](https://forums.unrealengine.com/u/LostScout)\
**Post date:** [November 3, 2015, 9:22pm UTC](https://forums.unrealengine.com/t/how-do-i-reference-my-particle-system-in-code/337253/3 "2015-11-03T21:22:49Z")

</div>

Thanks, that answered it.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_57741f591](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_57741f591](https://forums.unrealengine.com/u/anonymous_user_57741f591)\
**Post date:** [March 5, 2018, 12:10am UTC](https://forums.unrealengine.com/t/how-do-i-reference-my-particle-system-in-code/337253/4 "2018-03-05T00:10:12Z")

</div>

Hey Epic Games, you know what would be great? If when someone like me goes to [your documentation for the particle system component](https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Particles/UParticleSystemComponent/) I see these code snips at the top of the page. You guys should take a look at the documentation for SFML, it’s so much better…

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_284a909e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_284a909e](https://forums.unrealengine.com/u/anonymous_user_284a909e)\
**Post date:** [June 27, 2018, 2:25pm UTC](https://forums.unrealengine.com/t/how-do-i-reference-my-particle-system-in-code/337253/5 "2018-06-27T14:25:10Z")

</div>

For some reason I get an EXCEPTION\_ACCESS\_VIOLATION on the line of the FObjectFinder. Any idea how this could happen?

---

<div class="post-metadata">

**Author:** ![rootVIII](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@rootVIII](https://forums.unrealengine.com/u/rootVIII)\
**Post date:** [June 17, 2023, 4:14am UTC](https://forums.unrealengine.com/t/how-do-i-reference-my-particle-system-in-code/337253/6 "2023-06-17T04:14:50Z")

</div>

> [@anonymous\_user\_d4cefbf7](#):
>
> ```auto
> static ConstructorHelpers::FObjectFinder<UParticleSystem> PS(TEXT("ParticleSystem'/Game/StarterContent/Particles/P_Explosion.P_Explosion'"));
> PSC = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("MyPSC"));
> PSC->SetTemplate(PS.Object);
> 
> ```

Funny… I was hoping to do exactly what OP wanted to do… load the particle system with c++ only. I can confirm your advice worked for me in UE5.1.
