Adjusting speed of existing particles

I have a particle system and I want to control the velocity of emitted particles. I can modify the emission speed of new particles, but I want to also adjust the velocity of particles that already exist. I assumed I could do that by getting the particles, updating the velocities and setting the particles again, but when I then check the velocities the next frame, they’re unchanged.

Here’s the code:

void LateUpdate()
{
	if (mUpdateParticleSpeed)
	{
		mUpdateParticleSpeed = false;
		
		// Update particle velocities, assumes constant velocity
		int numParticles = particleSystem.particleCount;
		ParticleSystem.Particle[] particles = new ParticleSystem.Particle[numParticles];
		particleSystem.GetParticles(particles);

		for (int i = 0; i < particles.Length; i++)
		{
			var particle = particles*;*

_ particle.velocity = particle.velocity.normalized * mParticleSpeed;_

  •   	}*
    
  •   	particleSystem.SetParticles(particles, numParticles);*
    
  •   }*
    
  • }*
    Any suggestions as to the problem? I’ll post an update if I figure it out myself.
    Thanks.

Your code is all good, except you didn’t save the changed particle back to the array so it could be set back to the ParticleSystem.

var particle = particles*;*

particle.velocity = particle.velocity.normalized * mParticleSpeed;
particles = particle;

OR

particle.velocity = particle_.velocity.normalized * mParticleSpeed;
Also, you are probably already aware of the mUpdateParticleSpeed variable, but as the code is written now, this will only affect particles that have already been emitted. If they are starting to emit on play, then none will be affected because it will only run for one frame when no particles are emitted. I emitted that whole conditional statement to make sure the code worked.
- Josh_