- Home /
Problem with Execution Order
Hi guys I have a little problem. I have C# script called "Item" and I wanted to add him to the Execution Order but all other scripts showed up in list but not this one. I don't really know how fix it. (sorry for my english ;p)
Script:
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;
}
}
Your Item
class isn't a $$anonymous$$onoBehaviour, so it doesn't "execute" as far as Unity's concerned. Is there some other script that's creating, updating, or destroying it? That's the script you'll want to set an execution order for.
I have three scripts - item, iventory and item databse. $$anonymous$$y inventory script is adding items to the inventory from the item database before they exist. So I have to add an item script to execution order on the first place because item database requires item to exist other way I'll get an error again. I hope that's what you mean xD $$anonymous$$y english is awful :D In the tutorial script looked almost identical and has been added with no problems..
Sounds like you need the database to create an item before it's accessed.
I see two solutions:
$$anonymous$$ake sure the database always creates an item before you ever attempt an access. This might involve an execution order.
$$anonymous$$odify the database so that it can create an item on demand, the first time it's accessed ("lazy instantiation"). This involves some code changes.