# Spawning Niagara Systems via C++ code

**URL:** <https://forums.unrealengine.com/t/spawning-niagara-systems-via-c-code/501933>\
**Category:** FX\
**Tags:** laser, unreal-engine, question, UE4-27, CPP\
**Created:** [February 24, 2022, 11:08pm UTC](https://forums.unrealengine.com/t/spawning-niagara-systems-via-c-code/501933 "2022-02-24T23:08:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DukeSternutation](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DukeSternutation](https://forums.unrealengine.com/u/DukeSternutation)\
**Post date:** [February 24, 2022, 11:08pm UTC](https://forums.unrealengine.com/t/spawning-niagara-systems-via-c-code/501933/1 "2022-02-24T23:08:27Z")

</div>

Hello,

I am trying to create a laser beam in UE4 and C++. I have a Line Trace set up for my FPS, and am currently using DrawDebugLine() to see the trace in action in the editor.

However, I am not able to make the exact same thing work with UNiagaraSystems. I have tried debugging, and it does seem that the values are correct, but I see no system actually spawning.

I have attached a screenshot of my code in this post. The User Params here indicates Parameter EndPoint, which is an exposed param that I created for the Niagara System in the Editor and tied it to the System’s Beam Emitter Setup.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/b/b/2bb9d43a3c5cfdaf3d7fc05cdfb1fe744df663c9.png)

Here are the Debug Lines.

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/6/5/165caf7a6f2896d54cdb33cca249edd7e63f1ac8.png)

You can see the Beam Emitter Setup settings in the next image.

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/1/6/a16eef399ec82f700fe7ab403e5ed43f5aaa5714.png)

---

<div class="post-metadata">

**Author:** ![Michael.Galetzka](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/michael.galetzka/32/924122_2.png) [@Michael.Galetzka](https://forums.unrealengine.com/u/Michael.Galetzka)\
**Post date:** [March 7, 2022, 2:01pm UTC](https://forums.unrealengine.com/t/spawning-niagara-systems-via-c-code/501933/2 "2022-03-07T14:01:23Z")

</div>

Don’t modify the user parameters on the UNiagaraSystem, but use the setters on the spawned component instead.  
So `TeslaArc->SetVariableVec3()` for 4.27 and `TeslaArc->SetVariablePosition()` for 5.0.

---

<div class="post-metadata">

**Author:** ![DukeSternutation](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DukeSternutation](https://forums.unrealengine.com/u/DukeSternutation)\
**Post date:** [March 10, 2022, 7:10pm UTC](https://forums.unrealengine.com/t/spawning-niagara-systems-via-c-code/501933/3 "2022-03-10T19:10:33Z")

</div>

Thank you! That worked for me.

---

<div class="post-metadata">

**Author:** ![DEV7591](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DEV7591](https://forums.unrealengine.com/u/DEV7591)\
**Post date:** [March 9, 2023, 6:39pm UTC](https://forums.unrealengine.com/t/spawning-niagara-systems-via-c-code/501933/4 "2023-03-09T18:39:52Z")

</div>

> [@DukeSternutation](#):
>
> I have attached a screenshot of my code in this post

Don’t do it, it’s a bad practice, post the actual code instead.
