Unreal Niagara For Loop Example

Couldn’t find much examples for For-Loops in Niagara. Here a simple Example where for each particle, I read the position of EVERY other particle (via for-loop) and draw a line. Can be useful for Plexus-VFX (e.g. [Niagara 5.1] Plexus Mini Tutorial)

UnrealEditor_hSn3ATt4l1

2 Likes

Plexus
UnrealEditor_BCRQjAw5HJ

4 Likes

Oh my ! I’ve been trying to understand how to use the Map For node outside of simulation stage for years to be able to build some array based logic withing niagara scripts.

Thanks you so much for your findings @simonschreibt, a life savior as usual :hearts:

If I understand correclty, any function that is plugged before the Map For in the script AND is connected in some way to the “Map For Index” node will be triggered several time ? Do I get this right ? :thinking:

2 Likes

Glad to hear! I struggled with it too and couldn’t find much documentation about it. Then I stumbled across this post here where a screenshot shows a setup and it let me to experiment again: Niagara array for spawn particles - #4 by sarahlenker - FX - Epic Developer Community Forums

As far as I understand, everything is executed several times even without the Map For Index. This is just containing the current iteration number.

2 Likes

To add to this there’s this video by Tharle that I think sums up pretty well how the for loops work in Niagara

https://youtu.be/9CefjYXXLSs?si=3oz_7N0HIJ8qnGx2

2 Likes