I’ve scoured the web and found many examples of how to create new particles within a particle system and set their position, color and all that but I can’t seem to find anything on how to affect existing particles. GetParticles just returns the number of particles within an array of new particles you create.
How does one take all the particles that have already been emitted and, say, change their position?
GetParticles…Pass in array, returns an int, the amount, from the documentation → " Returns the number of particles written to the input particle array."
Nope
Yes, after you get the array of Particle type from the emitter, it specifically tell you that you must set after modifying, so yeah.
private ParticleSystem.Particle[] buffer = new ParticleSystem.Particle[100];
private void Update()
{
// Resize the buffer in case it is too small.
var particleCount = particleSystem.particleCount;
if (buffer.Length < particleCount)
{
buffer = new ParticleSystem.Particle[particleCount];
}
// Update particle positions.
particleSystem.GetParticles(buffer);
for (int i = 0; i < particleCount; i++)
{
buffer[i].position = 100 * Random.insideUnitSphere;
}
particleSystem.SetParticles(buffer, particleCount);
}
Landern - that’s for the legacy particle emitters, I’m talking about the shuriken particle system.
Alexzzzz - Get particles doesn’t actually get the particles as Landern said, it just returns the amount which I don’t get at all, couldn’t you just use particleCount. And as I said in my post I know how to create a new ParticleSystem.Particle array like in your example. The trouble I’m having is getting to the particles that already exist. It’s completely doable with the legacy particle emitters so I don’t know why they decided we shouldn’t be able to do it with shrunken.
My bad, when i was looking up the documentation i thought i was being very aware of the legacy particle system.
I do believe Alexzzzz is correct, particle is a struct, the array passed to GetParticles(size depending) will fill the array up and return the count as well, after manipulation, you have to update the particles invoking SetParticles since the array you filled is just a copy of what was emitted.