SerializeField GameObject Array Empty on Start

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Unity.VisualScripting;
using UnityEngine;

public class SpawnerAsteroids : MonoBehaviour
{
    public Vector2 backgroundScale = new Vector2(240, 120); // The scale of your background
    [SerializeField] int asteroidLimit = 50;
    [SerializeField] public List<GameObject> asteroidsOnMap;
    [SerializeField] public GameObject[] spawnersArr;

    // Start is called before the first frame update
    void Start()
    {
    }

    void Update()
    {
        if (asteroidsOnMap.Count < asteroidLimit)
            instantiateAsteroid();
    }

    private void instantiateAsteroid()
    {
        Debug.Log("Number of spawners available: " + spawnersArr.Length);
        if (spawnersArr.Length > 0)
        {
            GameObject spawnerChosen = spawnersArr[Random.Range(0, spawnersArr.Length)];
            if (spawnerChosen != null && spawnerChosen.GetComponent<Spawner>() != null)
            {
                spawnerChosen.GetComponent<Spawner>().canSpawn = true;
                asteroidsOnMap.Add(spawnerChosen.GetComponent<Spawner>().instantiatedAsteroid);
                Debug.Log("Asteroid instantiated.");
            }
            else
            {
                Debug.LogError("SpawnerChosen is null or does not have a Spawner component.");
            }
        }
        else
        {
            Debug.LogError("Spawner array is empty.");
        }
    }
}

Hey everyone, i need some help with something here… I have 34 game objects in my level that are used for spawners. I’m trying to add these objects to an array of objects in a script so I can administer those spawns. I’m using a SerializeField GameObject[ ] in the script and adding the objects in Unity Editor. The issue is that if I print the length of the array when the game runs, it shows as empty… Any ideas why? I’ll show the script I have and the Inspector.

Don’t post screenshots of code, use the code tags.

Okay, can you help tho? lol

I’m not going to try and analyse and debug a screenshot.

My first thought is to check for duplicates of the script, but that’s harder to miss when you’re using the console.

Is that a screenshot of the Inspector while in play mode?

Just a quick tangent: I don’t recommend using GameObject as the type here if you’re just going to reference the component on it. Use an array of that component. This has the advantage you won’t accidentally link up an object without that component, and it’s slightly higher performance too.

[SerializeField] public Spawner[] spawnersArr;