Niagara System: Manually Spawn Particles Through C++

Hi everyone,

I have a requirement to be able to manually spawn particles in a Niagara system from C++.

I am making a game a little like Total War, with a unit of around 100 soldiers firing in volleys. Each soldier can have a different position and aim direction, and they don’t all fire at exactly the same time. I want to have a tracer effect to give the player some visual feedback as to what their soldiers are firing at and to give a little more impact to firing.

Rather than spawn 100 individual Niagara systems per soldier, I’d rather have a single persistent system which can spawn the effect on demand when a soldier fires. My challenge however is I can’t figure out a way to do this. Here is what I’ve done:

  1. Created a Niagara System which spawns a single particle. Two user parameters are used to set the starting world position of the particle, and the direction it should move in.
  2. Set the system’s inactive response to “Complete” and loop behaviour to “Once”, and the emitter inactive response is “Continue” and the loop behaviour is also “Once”
  3. Created a Niagara Component in the unit actor which uses that system template, but is set to start as inactive

What I’m struggling with is how to essentially say to the Niagara system “spawn a particle at this location and in this direction” and have it play the effect. I’m currently using SetVectorParameter to the soldier’s location and aim rotation, and then Activate(true) to fire the projectile.

This kind of works, but if soldiers fire within a short time frame of each other, the Activate function call cancels out a lot of the particle spawning, so if 10 soldiers all fire together, only the last soldier will actually spawn a projectile. I assume this is because constantly calling Activate(true) cancels any previous particle spawning if done too quickly.

What is the correct way to get around this? Thanks!

Use SetVectorParameterArray,You can emit multiple particles at the same time.But you need to use NIagara Scripts to make corresponding modules, take the array length as the number of generated particles (Make spawn info), and set the position and velocity for each particle,forget my poor english…

1 Like