Array index out of range. But it doesn't appear to be.

So, I have these variables:

public Sprite[] items;
    public Image[] slots;

In editor, I filled 63 items with sprites and 36 slots with UI images /w text & image as children from scene.
Then I have this function:

void LoadItems(int count)
    {
        for (int i = 0; i < count; i++)
        {
                
                if (character.items*.count > 0)*

{
//Debug.Log(“a”);
slots*.color = new Color(1, 1, 1, 1);*
slots_.sprite = items[character.items*.id];
slots.transform.GetChild(0).GetComponent().text = character.items.count.ToString();
}
else
{_

_slots.sprite = null;_
_slots.transform.GetChild(0).GetComponent().text = null;_
_slots.color = new Color(1, 1, 1, 0);
}
}
}
Which is called from 2 places which call errors:
if (Time.frameCount == 1 && character != null)
{
LoadItems(slots.Length);
}
//---------------
if (Input.GetMouseButton(0) || Input.GetMouseButton(1))
{
Debug.Log(“ai”);
LoadItems(9);
}*_

Error: IndexOutOfRangeException: Array index is out of range.
I really don’t know, what is wrong. Maybe it’s the editor?
Oh and character.items is this:
public Item[] items;
//This is Image script
[System.Serializable]
public class Item {

public int id;
public byte count;
public string info;

public Item(int id, byte count, string info)
{
this.id = id;
this.count = count;
this.info = info;
}
}
Edit: items[] is just an array of sprites, used to represent textures. I have 63 in-game textures, so I have 63 Sprites, 1 for each item. Slots on the other hand are actual on-screen inventory slots, where the items are stored. And character.items is basically the same array as slots, it holds data of each slot, what the item is (id, also used in Sprite[] items), what is it’s count, and additional info.

Hi, ok, I check your code and seems everything it is ok, but maybe you forgot a little detail:

public Sprite[] items = new Sprite[0];
public Image[] slots = new Image[0];

//In some part of the code
items = new Sprites[5]; // this creates a new array with five elements.
images = new Image[10]; //Same as before.

if (items.Length < images.Length) { //Of course it is. ;-)
    //Do Something here. . .
}

If you don’t do this, you will get the Debug Error: out of range, count 1 - existing 0.

Okay, thanks everyone, who answered, it DID help me. The problem was: IDK why, but unity keeps screwing up it’s editor assignments. So, I decided to assign every sprite and image in script, using @ArturoSR answer. Thanks to you all.