For Loop with If Statement Inside giving Argument of Range

So I have a list that I want to go through and change some variables for attached ParticleSystems.
However, there are some GameObjects inside the list (they have to be in it) that Don’t have ParticleSystems components.

for(int i = 0; i < particlesList.Count; i++)
        {
            if(particlesList[i].GetComponent<ParticleSystem> () != null)
            {
                particlesList[i].particleSystem.startSize = particleSizes[i] * scaleFloat;
                particlesList[i].particleSystem.startSpeed = particleSpeeds[i] * scaleFloat;
                particlesList[i].transform.localScale = (particleScales[i] * scaleFloat);
            }
        }

With the if statement I get the out of range error which doesn’t make sense to me.
Without the if statement, It tells me I’m trying to access a component “ParticleSystem” that doesn’t exist on the GameObject. Then tells me to either check if it has one first, or create one for it.

Does anyone have any ideas?

Which line gives the error?
Do particlesList, particleSizes, particleSpeeds and particleScales all have the same length?

You’re exactly right hpjohn! The lists aren’t the same sizes :sweat_smile:. Would you happen to have any solutions off the top of your head to keep from having to add another item the other lists?

Is the size of the other lists always the same as the count of objects that actually have pSystems?

if yes:

 int j =0;
  for(int i = 0; i < particlesList.Count; i++)
            {
                if(particlesList[i].GetComponent<ParticleSystem> () != null)
                {
                    particlesList[i].particleSystem.startSize = particleSizes[j] * scaleFloat;
                    particlesList[i].particleSystem.startSpeed = particleSpeeds[j] * scaleFloat;
                    particlesList[i].transform.localScale = (particleScales[j] * scaleFloat);
                    j++;
                }
            }

Awesome, that’s it John. Seems so obvious now but I probably would have spent days trying to figure it out. Thanks so much!