I’m interested in using a sprite sheet (or multiple materials) to generate a CPU particle effect. But what I’d like is for each particle to be assigned randomly to a single sprite. Is this possible? Or am I better off using a different emitter for each sprite and just layering them on top of each other?
This would be fairly easy on a GPU sim, but I need the Death Event, so that’s out of the question.
You can achieve that effect using “Renderer Visibility: Use a renderer visibility tag to show particles with that tag, and hide particles without it.”
In the “Niagara System”:
In the “Emitter” add all the “Sprite Renderers” that you require and assign in the “Renderer Visibility” property a unique value to each one as a sequential. (The “Renderer Visibility” is internally assigned the “Particles.VisibilityTag” attribute.)
In “Parameters” add the “VisibilityTag” to “Particle Attributes”
In the “Emitter” add to “Particle Spawn” a “Set new or existing parameter directly” and here add the “Particles.VisibilityTag”, change it to “Random Range Int” and assign the minimum and maximum value used from Step 1 .
For sprite sheet:
The logic in this case is to randomly choose the row and column number within the Sprite Sheet where the sprite that you want to display in the material is located.
Material Considerations:
This must be able to receive by “Dynamic Material Parameters” at least the 2 parameters, one for the row and the other for the chosen column.
How to construct the material is at your discretion.
In the “Emitter”:
In the “Sprite Renderer” assign in “Material” the one that was previously created.
Add to “Particle Spawn” a “Set new or existing parameter directly” and here add an int32 type for the “column to choose”, change it to “Random Range Int” and assign the minimum value of 0 and the maximum will be the total columns minus 1 (Example: If the Sprite Sheet has 20 columns then 19 is assigned. Since the count starts with 0 in the material).
Add to “Particle Spawn” a “Set new or existing parameter directly” and here add an int32 type for the “row to choose”, change it to “Random Range Int” and assign the minimum value of 0 and the maximum will be the total rows minus 1 (Example: If the Sprite Sheet has 15 rows then 14 is assigned. Since the count starts with 0 in the material).
Add to “Particle Spawn” a “Dynamic Material Parameters” and change both parameters to “Multiply Float by Int”, leave the Float value with 1 and change the Integer to “Particles. The name you gave to the parameter in the step 2 or 3 depending on how you order them”