Epic Games distributes a project called “Content Examples,” which is a collection of various sample projects showcasing different features of Unreal Engine. Since UE4.26, there is a map called Niagara Advanced.
This map contains a wealth of useful samples, including examples of new Niagara features and practical applications. Upon reviewing the implementations, there’s a lot to learn.
This article will break down these samples into multiple parts for detailed explanations.
By the way, Content Examples can be downloaded from this link in Fab. Please note that the content may vary depending on the version of UE.
※Note: This blog is written based on UE4.26 Contents Example, so it might differ from the latest version in small details, but the concept itself explained here won’t change
TLDR;)
- With the Particle Attribute Reader, you can obtain attribute information from the same emitter or another emitter’s particles.
- To fetch the information, you need to specify which particle’s data to retrieve using either the Execution Index or Particle ID.
- The reader and the data source must be the same Sim Target.
Introduction
This article will explain the Particle Attribute Reader.
The Particle Attribute Reader has been available since version 4.25, but in version 4.26, it has more samples and has become a very useful feature. In this article, I will explain it in more detail.
As the name suggests, it allows you to retrieve attribute data from other emitters or the same emitter’s particles by specifying the Execution Index or ID.
In this explanation, we will go over three samples in Niagara Advanced: “2.1 Particle Attribute Reader,” “2.2 Follow The Leader 1.0,” and “2.3 Spawn Particles Another Emitter,” to help you understand the basics of this feature.
The Particle Attribute Reader can be used in both CPU Sim and GPU Sim, but the reader and the target particle must share the same Sim Target.
2.1 Particle Attribute Reader
Note: The GIF image above shows two Niagara Systems: one at the top and the Ring at the bottom. Since the top one is simple, we will focus on explaining the Ring at the bottom.
A particle orbits along a circle, and its color changes as it passes through certain points.
The system consists of two emitters: Leader and Ring.
The Leader emitter has a single sprite that continuously rotates in a circle. It completes a full rotation during its lifetime, and its color is randomly set upon spawning.
The Ring emitter has particles evenly distributed in a circle. When no Leader is present, these particles remain white. By retrieving and applying the Leader’s color attribute, the particles change color accordingly.
By the way, to distribute the particles evenly in a circle, the Torus Location module is used. The Distribution is set to Direct Mode, with the Radius Position set to a constant and U Position using the Return Normalized Exec Index. This is a handy piece of information.
Now, for the important part: the Particle Attribute Reader. It is initialized at Emitter Spawn. By specifying the name of the emitter you want to read from in the Emitter Name, you can target the emitter.。
Then, using the “Read Color from Emitter” (Scratch Pad module), it reads and applies the color data from the Leader.
Using the “Get {Data Type} By Index” node, you input the Particle Attribute Reader and Particle Index, and specify the attribute name you wish to retrieve.
The Index is the same as the Execution Index. Since the Leader only has one particle, entering 0 will retrieve the data from that particle.
In other parts of the Scratch Pad, the distance between the current particle’s position and the Leader’s position is checked. If it’s smaller than a set threshold, the current particle’s color is changed to match the Leader’s color.
This creates the effect where particles change color as the Leader passes by.
It’s a simple but foundational concept.
2.2 Follow The Leader 1.0
In this sample, red particles float around, and green particles maintain a certain distance while following them.
Like the previous example, it consists of two emitters: Leader and Followers.
The Leader is a red floating object. It spawns 22 particles using Spawn Burst Instantaneous and is kept floating with forces like Curl Noise Force and Vortex Force.
One key point to note is that the Emitter Properties have the “Requires Persistent IDs” checkbox enabled. This ensures that when the Particle Attribute Reader retrieves data, it uses Particle ID instead of Execution Index.
Execution Index refers to the order in which the processing is done. When particles are continuously born and die, new particles might get the same Execution Index as dead particles. On the other hand, Particle ID is unique and remains consistent, so there’s no risk of overlap.
Depending on the situation, you need to decide whether to use Execution Index or Particle ID.
Next, let’s look at the Followers. As with the previous sample, Particle Attribute Reader is initialized at Emitter Spawn.
An Attribute called “Offset” is created, which stores a random vector of a specific length. This is used to maintain a set distance from the Leader.
In the Initialize Followers section, the Particle ID of the Leader is determined, and in the Update Followers section, the particle follows the Leader’s movement. Both are Scratch Pad Module.
Let’s focus on Initialize Followers.
First, from the Particle Attribute Reader, “Get Num Particles” retrieves the total number of particles in the emitter at that moment. Since there are 22 particles, subtracting 1 gives an index range of 0 to 21. Using “Calculate Random Range Index,” a random index between 0 and 21 is selected.
This index is then used with “Get ID at Spawn Index” to retrieve the Particle ID.
That Particle ID is saved as the Leader’s ID. This allows the particle to determine which Leader to follow.
Now, using this ID, “Get Vector by ID” fetches the Leader’s position (Attribute Name is None in the picture but it’s just a mistake and should be Position). The previously set Offset value is added to it to define the follower’s position.
Next, in the Update Followers section, Each of particles retrieves Position of the Leader particle it follows by LeaderID which was set in Initialize Followers and adds velocity towards the position added by Offset.
Instead of directly overwriting the position, the velocity is used, adding a bit of “play” to make the following motion feel more natural.
Finally, since velocity is used, be sure to include the Solve Forces and Velocity module to move the particle.
2.3 Spawn Particles Another Emitter
Finally, let’s look at the “Spawn Particles Another Emitter” sample. In this system, particles are randomly emitted, and new particles are spawned along their trajectory, creating an effect similar to Ribbon Renderer.
However, since Ribbon Renderer does not work in GPU Sim, this approach is noteworthy because it achieves a similar effect in GPU Sim.
Also, unlike the previous examples, this sample doesn’t require implementing Scratch Pad manually. Instead, UE provides specialized modules that work with other emitters to control particle behavior.
Let’s take a closer look.
As usual, it consists of two emitters: Leaders and Followers.
The Leaders emitter simply releases particles upward at random. We won’t go into detail here.
The important part with the Followers is the use of two modules: “Spawn Particles from Other Emitter” and “Sample Particles from Other Emitter.” These two modules must be used together.
First, let’s look at the “Spawn Particles from Other Emitter.”
You input the name of the emitter that will be the source of the particles.
The Spawn Rate defines how many particles to spawn per second, and if you check “Calculate Spawn Rate Per Particle,” the spawn rate will be applied per particle of the source emitter. In this case, 22 x 50 = 1100 particles will be spawned per second.
“Spawn Rate Per Particle Cap” sets the upper limit of particles spawned per source particle.
Next, let’s look at “Sample Particles from Other Emitter.”
Emitter Sampling Mode has two options: Sequential and Random. Choosing Random will spawn particles from randomly selected particles of the source emitter. Sequential will select them in order.
The Filtering section allows you to filter source particles with three settings.
The other options pertain to the particle’s basic attributes, like Position, Color, Velocity, and Mass, and you can choose whether to inherit values from the source emitter.
When you click the dropdown, you can select from Disabled, Apply to Attribute, or Output Only. Choosing Apply to Attribute will apply the source particle’s value to the spawned particle’s attributes. Output Only will keep the value as an output attribute without applying it.
This is useful when you only need the data without modifying the particle.
With these settings, it’s easy to spawn new particles from another emitter’s particles and inherit their attributes.
Conclusion
The need to retrieve data from other particles is quite common, and thanks to the Particle Attribute Reader, it’s now much easier to do.
In the past, we would use an Event Handler to trigger an event and retrieve data from other particles, but using the Particle Attribute Reader is simpler and more performance-friendly.
I think this is a great feature, and as expected from Niagara.
Enjoy your CG journey!