Q:

How to add non-monobehaviour script to script execution order

 
So I'm trying to create an inventory system based on a tutorial, and at some point(specifically when I was trying to add to a list the "items", with icons and everyhting) I get an out of range error.The tutorial specifies that in order to remove that error I have to set a specific execution order for the 3 scripts I'm currently using.

The problem is, one of the scripts is not a monobehaviour , and while he simply adds it to the order, I can't seem to do it, and I don't see another way of removing the error.

using UnityEngine;
 
using System.Collections;

[System.Serializable]

    public class Item {
    public string itemName;
    public int itemID;
    public string itemDesc;
    public Texture2D itemIcon;
    public int itemPower;
    public int itemSpeed;
    public ItemType itemType;

    public enum ItemType {
        Weapon,
        Consumable,
        Quest
    }

    public Item (string name, int id, string desc, int power, int speed, ItemType type)
    {
        itemName = name;
        itemID = id;
        itemDesc = desc;
        itemIcon = Resources.Load<Texture2D> ("Item Icons/"  + name);
        itemPower = power;
        itemSpeed = speed;
        itemType = type;
    }

}

I don't know if they're necesary, but here are the other 2 scripts

using UnityEngine;

using System.Collections;

using System.Collections.Generic;

public class ItemDatabase : MonoBehaviour {
    public List<Item> items = new List<Item> ();

    void Start ()
    {
        items.Add (new Item ("Rotten Apple",0,"Things can be seen moving under the surface of this putrid apple",2,0, Item.ItemType.Weapon));
    }
}

using UnityEngine;

using System.Collections;

using System.Collections.Generic;

public class Inventory : MonoBehaviour {
    public List<Item> inventory = new List<Item> ();
    public ItemDatabase database;

    // Use this for initialization
    void Start () {
        database = GameObject.FindGameObjectWithTag ("Item Database").GetComponent<ItemDatabase>();
        inventory.Add (database.items[0]);
        inventory.Add (database.items [1]);
            
    }
    
    void OnGUI ()
    {
        for (int i = 0; i < inventory.Count; i++)
        {
            GUI.Label (new Rect (10,i * 20, 200, 50), inventory[i].itemName);
        }
    }

}

A:

Execution order for non-monobehaviour scripts is determined by the order you execute them from your monobehaviours code :)
Seialized fields are initializing before all Awake() and Start() calls.
Seems that you just need to set ItemDatabase execution time earlier than Inventory. And database should contain not less items than you are trying to extract.

