Why is my loop playing more times than given?

I am following the example here Unity - Scripting API: ParticleSystem.GetParticles but my loop seems to be playing more times than given by the relevant variable. As you can see from the screenshot below numParticlesAlive has a value of 2 but the loop was executed 18 times instead, any clues?

void CreateList(){
       
        int numParticlesAlive = m_System.GetParticles(m_Particles);
        print (numParticlesAlive);

        for (int i = 0; i < numParticlesAlive; i++) {
           particlePosition = m_Particles[i].position;
           particleList.Add(particlePosition);
           print(particleList[i]);
        }
    }

Oh i found it, i was calling it from a GetKey instead of GetKeyDown, you may delete this thread.

Don’t do that. The point of the forum is for everybody to learn more about Unity.

1 Like