Niagara - Export Particle Data

Sep 17, 2020.Knowledge
Originally written by Ryan B.

For 4.25 we introduced an experimental feature for exporting particle data and generating blueprint events for CPU particles in Niagara. The new UNiagaraDataInterfaceExport data interface can export Position, Size and Velocity to a blueprint that implements INiagaraParticleCallbackHandler. This is done through the Store Particle Data node, that can be added to a custom Niagara module script.

As an example here’s the system overview highlighting the relevant modules. This system was created based on the fountain template.

There are two User Parameters, Callback and ExportData. Callback is an Object, and will be assigned to the object that implements the callback handler interface. ExportData is the Export Data, Data Interface, and is used as the linked input into the custom Export Data module. Note that ExportData sets its Callback Handler to User.Callback.

Here’s the custom Export Data Module graph:

It’s a bare minimum setup, that only exports Position Information. You can export any float and any two Vector 3 parameters you’d like, as you can see in the graph. The Store Data input will determine whether or not data is exported to the blueprint on that specific execution, which can be used to trigger events. For example if you only wanted to export data in response to a particle collision you can use Particles.HasCollided as the input for Store Data.

Storing the Success bool that is output is necessary for compilation. In this example it’s not used for anything, but you may wish to respond differently if the data is not exported. In the Emitter’s Particle Update after the Export Data module its output is assigned to a new Particle parameter, so it could be used elsewhere if desired.

Store Particle Data will trigger the Event Receive Particle Data on the Callback Handler object, which is why the object needs to implement the Particle Callback Handler interface. Here’s the corresponding event graph of the callback handler that simply prints out the particle’s position:

In this example the actor also has the Niagara component with this system as its asset. In its construction script it sets the user variable so the appropriate object will be assigned to the callback handler, in this case it’s a reference to self: