I have a simple vector array to spawn my fontain fx from a single emitter in many coordinates, but how can I use a bool array or other to control the spawning of particles in one of those coordinates independently of others
Hi @RICK_AV,
This question may be more complicated than you realize. Since all of your particle spawners are within the same emitter, it’s randomly choosing one of your array locations to spawn at. Therefore, to overwrite that, you’re going to have to manually tell the system which location to spawn at.
In this solution below, I’ve moved the random array location into a scratch pad. Here, you can input a location to not spawn at, and the random int generator will run through up to two random passses to avoid that number. If it still hits that number, it will just increase the array location by 1. If you set the location to avoid at -1, it will spawn at all of the locations.
You could expand this solution out to account for more than 1 location, but that would involve turning the int input value into an array and using a for loop, which is only supported in Niagara HLSL. If you need this setup, let me know and I can help you run through it.
Note that your “Array Sampling Mode” MUST be set to “Direct Set” (4th screenshot)
@sarahlenker Wow I’m very grateful to you! I don’t know what I’d do without you.
Works fine, but yes, i need some help with hlsl and array for input, If it’s not too much trouble for you
@RICK_AV
Well, I learned a lot about Niagara arrays and loops today.
It turns out that Niagara HLSL does not accept dynamic arrays as inputs, they must be hard-coded, which won’t work because you want to set the values dynamically.
I’ve come up with a solution to iterate through an array, but note that it results in particles being not quite evenly distributed (locations earlier on your array will have less particles related to the amount of locations to avoid), and comes with a few limitations. Is this an ideal way to work with arrays? No. But this was the best I could figure out working within Niagara’s limitations. If anyone else on this forum knows something that I’ve missed, please chime in.
-Your emitter must be a GPU emitter- the ingrained For Loop doesn’t work on CPU emitters.
-Your “Locations to Avoid” array values must increase- not decrease- as the array grows. Numbers can be repeated, just not be lower than the previous number.
First, assign your particles a new value of “RandInt”, which is a random range from 0 to the number of Postion array elemnts. You’ll need to set the max as a Scratch Dynamic Input
Then, you’ll need a new scratch pad module that looks like this:
I tried to label everything clearly so you understand what’s happening here, but let me know if you have any questions.
Then, we’ll direct set the particle’s position using the new RandInt value and selecting from our position array. I’m setting it outside of the previous scratch pad just to avoid any wonkiness with the for loop.
Finally, we need a module to kill particles. This will only kill particles in the event that the last position is turned off, as we have no way to reliably randomly reassign those particles to lower indexes.
I hope this helps!