Niagara GPU particles index

Hi,

I spawn a bunch of particles that lives forever and I need to read attributes of specific particles in the same emitter using Particle attributes reader.

I noticed that the indexes of particles change constantly when you have more than 64 particles in GPU mode. ( does not occur on CPU mode or with less than 64 particles )

Since you can only use particles indexes to read an attribute, I need the indexes to remain the same in GPU mode.

Anyone has a workaround for this issue?
Thanks!

1 Like

maybe this will help.

Thanks for the reply!
I tried getting the ID from an index on spawn and storing the value, but it seems that it’s getting invalid and defaults to (0,0)

image

If you’re getting the ID from “particle index” (precisely “Execution Index”, not “UniqueID”), make sure you get it during Particle Spawn stage (Get ID at Spawn Index) or only at the first frame during Particle Update stage (with Transient.FirstFrame as the bool to select between the freshly obtained ID and already stored ID), because Execution Index also shuffle similar to ID.


Again, courtesy of Niels of the knowledge about the Niagara particle ID.

3 Likes

Haaa I see,

Let’s say I want the particle that spawned before as ParentID.
Can you use Execution Index -1 ( and make sure it doesn’t go below 0 )?
Or will execution index give you arbitrary numbers ?

I also found out there is a node called Get Particle Index From ID Table that let you pass the spawned index and gives you the current index and that worked for my use case as well.

AFAIC, -1 index begets “false” valid output from PAR Get node. You can either do a max(index, 0), or kill the child particle if PAR Get gives invalid output by setting false value to the “Alive” attribute. However, You should do a logic AND operation between the particle’s current Alive state with the PAR Get valid output to avoid “reviving” a dead particle (Niels told me about this bit :wink:)

I haven’t tried Get Index from ID Table yet, sounds quite fun.

1 Like

Hey!
I tried using Get ID at spawned index using max(0, execution index - 1) to get the parent.
While this works on the GPU now, the CPU mode doesn’t work any more. (IDs are wrong after a certain amount of particles)

GPU Result

CPU Result

The execution index seems fine on both CPU and GPU

Any idea on how to make it work on both CPU and GPU?
Thanks!

I need some clarification first. When we talk about “Execution Index”, it is represented in Niagara Debugger as “Particle(n)” when “Show Particle Index” is enabled AND there is a valid particle attribute to be displayed. So I am not sure how you store that “ExeIndex” attribute as shown in your screenshot. If I understand correctly it has to be your custom particle attribute.

hey!
yes, to be clear I’m doing a spawn burst once with particles that live forever.
In my screen shot I was outputing the Execution index to a custom int attribute and display that attribute.

That being said, I also tried the same using the debugger option “Show Particle Index” and also using UniqueID instead of execution index to get the previous particle.

In each case, the order is fine and I can get the correct ID on GPU, but on CPU the order is still good, but the previous ID is wrong.

Also note that it’s breaking on the CPU when you have over 512 particles

Less than 512 particles:

More than 512 particles:

At that point, the indexes goes crazy and the parentIdTag ( value from Get ID at spawn index) is wrong.

After speaking with an employee from Epic we concluded that there is a bug with Get ID at Spawn Index on the CPU. After more than 512 particles it starts doing parallel work and at that time the result is wrong. They opened a JIRA for it.

To fix the problem we can disable the parallelization by using the command vm.Parallel 0 that fixes the issue, but probably comes with a loss of performance when using a lot of particles.

4 Likes