[Solved!]Storing gameObjects in an array on Instantiate

Hi, i’ve been trying to make a custom particle system that instead of constantly respawning the particles, it simply relocates them. To do this, I created an array with 200 elements, and iterated through it as they were spawned, storing them into it in the process, like so:

GameObject[] flares;
void Start(){
        col = GetComponent<Collider>();
        flares = new GameObject[200];

for (; flaresIterator < 200; flaresIterator++)
        {
            selectedPos = this.transform.position + Random.insideUnitSphere * flareradius;
            if (col.bounds.Contains(selectedPos))
            {
                flares[flaresIterator] = (GameObject)Instantiate(orangeFlare, selectedPos, Random.rotation,);
                Debug.Log(flares[flaresIterator]);
            }
        }
}

This code is intended to spawn a plethora of particles within the bounds of the object, but for some reason, it doesn’t seem to be storing them into the array at all (The debug statement always returns null), but it IS instantiating them. I feel like i’m forgetting something rather basic, but have been fidgeting with it for like a half hour with no progress. Anyone know what i’m missing?

for (; flaresIterator < 200; flaresIterator++)

you seem to be missing the first argument

int flaresIterator = 0

The variable is already declared outside of the Start function, so I don’t actually need the first argument. (I could put it there for readability but meh)

(GameObject)Instantiate(orangeFlare, selectedPos, Random.rotation,);

Is that comma after Random.rotation supposed to be there? Not sure how that would affect it

Changed some stuff (just where my debug statements were, and removed that weird comma), problem seems to be it’s not storing it in the array. If I do
Debug.Log(Instantiate(blablabla));
it displays “OrangeFlare(Clone)”, but if I do

flares[flareIterator] = Instantiate(blablabla)
Debug.Log(flares[flaresIterator]);

it says that it’s null. Did I set up/use the array right?
I have the weirdest friggin’ problems, I swear my computer is literally haunted…

Still don’t comprehend why, but storing the gameobjects into another object, then storing THAT into the array works. Example here (psebocode):

void Start(){
gameObjectArray = new GameObject[particleamount];
do{
particle position = Stufftofindparticleposition();
}while (insertvaliditycheckhere(position))
for(int iterator = 0; iterator < particleamount; iterator++){
GameObject obj = Instantiate(gameObject, position, rotation);
gameObjectArray[iterator] = obj;
//Congrats, you have an array of particles. It's what you've always wanted, always been searching for in the night, those long days and wind swept plains never once wavered your faith, and now your ignorance to the heresies of the nay sayers and unbelievers has been rewarded
}