IndexOutOfRangeException when instantiating object that I know is there

Hello,

I’ve got a simple program that I’m having an issue with.

Essentially, in my scene I have a button that is instantiated using canvas in ButtonManager.cs. Attached to it as an OnClick is a function in PieceManager.cs that instantiates an object from a GameObject array.

Code:

ButtonManager.cs

public Button spawnButton;

void Start()
{
    Instantiate<Button>(spawnButton, new Vector3(342, 43, 0), Quaternion.identity).transform.SetParent(transform);

    //The OnClick is attached to the prefab in the editor

}

void Update() { }

PieceManager.cs

public GameObject[] pieces;
void Start()
{
    pieces = new GameObject[29];
    //add all the pieces to the array
    for (int i = 0; i < pieces.Length; i++)
    {
        pieces *= Resources.Load<GameObject>("Block" + i.ToString());*

}
}
void Update(){}
public void SpawnPieces()
{
Instantiate(pieces[0], new Vector3(0, 0, 0), Quaternion.identity).transform.SetParent(transform);
}
I made the array of GameObjects public so I could look at it in the inspector and I confirmed that it was filling the array properly. So, it seems as if my pieces array is showing up as empty to the button, when it’s actually not.
Any help would be appreciated, and I’ll try to respond with more information if you need it.
Thanks!

You can not attach a reference to your PieceManager’s SpawnPieces method inside a prefab. A prefab can never reference something in a scene. So you may reference a PieceManager script on another prefab. However that means you would call the method on the prefab, not on the object in your scene.