How to get the ID of the last Niagara particle spawned and remove it?

Hi all,

I have a Niagara system that uses two custom modules: one that spawns a new particle based on a Blueprint event (thanks to another answer on here for that :slight_smile: ) and another that kills a specific particle, selected by its ID, on a seperate event. The expected result is that I can press one key and spawn particles, and press another to remove them in reverse order.

However, I’m looking for a way to select the last particle spawned. I have so far got the following module that selects the paricle with Niagara ID index ‘3’ and removes that, but with particles if one is removed from that index the next particle spawned wil replace that/reuse the index, meaning the order spawned will not match the order of the particle ID indices. Here is the Scratch Pad:

The Niagara ID object also has a tag, which I presume is unique and may be better to use, but Im looking for a way to get the last particle spawned, and for that to be replaced by the next last particle spawned, so if I were to have 5 particles, I could remove them one by one with the fifth, then the fourth, then third, etc.

Would I need to store the particles created in another array and access that to get their IDs, and manipulate that array (as a User Parameter maybe?) or is there already an existing parameter I could access?

Many thanks :pray:

Try the setting “Requires Persistent IDs” on the Emitter Properties.

If that doesn’t work you might want to try reading from Particle Attribute Reader where you have access to the Index and the ID.

In case anyone is still looking for a solution for this.
It seems that in the “particle update” stage the “Exec Index” of each particle corresponds to the order of spawning.
Particle spawns later will always be at the end of the exec queue.And removing and spawning particles do not create gap in the execindex value.
So maybe using the execindex instead of Niagara ID is easier.
Like you have 6 particles and the “uniqueID - ExecIndex” pair is 0-0,1-1,2-2.3-3,4-4,5-5.
Then the third and fourth particle (UniqueID 2 and 3) is removed,the “unique ID - ExecIndex” of the remaining 4 particles next tick will be 0-0,1-1,4-2,5-3.
And then you spawn 2 new particles, the “unique ID - ExecIndex” pair will be 0-0,1-1,4-2,5-3,6-4,7-5.
So for example if you want to remove the second oldest particle,just remove the particle whose execindex == 1 and it’s done

4 Likes