Has anyone notice this or I am just totally new?

In unity CSharp, I was trying to create an inventory system.
So I deleted “void Start()” at first cause this usually confused me.
then my “idatabase” won’t work without Start().

Does anyone konw why? Here is my code:

public class ItemData : MonoBehaviour {

public List<Item> Idatabase = new List<Item>();


	
	Item fish = new Item (001, "Fish", "food");
	Item water = new Item(002,"Water","water");
	Idatabase.Add (fish);
	Idatabase.Add (water);
	Debug.Log (Idatabase[0].Name);
	Debug.Log (Idatabase [1].Name);
}

public class Item {
	public int ID;
	public string Name;
	public string Type;

public Item(int newID,string newName,string newType){
	ID = newID;
	Name = newName;
    Type = newType;
}

}

You need to enclose your code into a method and then call it (except for the definitions). If you include it in Start(), Unity will automatically call everything inside at game start. But you can write your own (public) method, then instantiate the class somewhere else and call the methods.

A class contains property declarations and methods. The declarations and the constructor will be called whenever it is instantiated, which is done by Unity when you add it to a component.

Every other method of it has to be explicitly called. Unity has a huge list of predefined method signatures that you can implement to be invoked by Unity.

Some examples:

void Awake() // after the constructor this is the first one to be called when the scene is initialized. access to your own components is possible

void Start() // called in the second round of scene initialization. access to components of other gamesobjects is possible

void Update() // called once per frame

and like… one million On…() methods to get notified of events like collisions, mouse interaction, etc.

As those methods are called through some reflection mechanism (Messages), you are not really implementing an interface for them.