Cannot Assign Material To Object

Hi guys, I’m having a problem with assigning a material to an Object which is an instance of a class. In the Inspector, I’ve dragged the Material I want but when I print out the value of the material, it gives me null.

public class Monster extends MonoBehaviour {
   var material : Material;

   //Constructor
   public function Monster() {
   print(material); //This gives null even though the material     is clearly assigned in the Inspector
   }
}

//I call this constructor using:
var monster : Monster = new Monster();

I’m completely stumped on this so any help is much appreciated.

you shouldn’t implement (and definitely shouldn’t call) constructors for MonoBehaviours. One of the reasons for this is that in the best-case scenario, your constructor will be called when the game starts, and then the contents of the instance will be over-written by de-serialized data as Unity loads up your scene file.

If you want initialization code to run when the game starts, use Start() or Awake(). Awake() will be called immediately as part of the instantiation process. Start() will be called before the first Update() call that the newly instantiated object gets.

ScriptableObjects are non-Behaviour Objects that Unity lets you serialize as stand-alone assets. They’re for storing data that doesn’t belong to a specific level or prefab. GUISkins are a good example of a ScriptableObject.

Source : Check here for better explanation