Classes, MonoBehaviours C#

Okay, So I am new to unity programming.And I wanted to know the difference between, Advantages and dis-Advantages about Classes and MonoBehaviours.

Because I was trying to instantiate something in a class but the compiler says the method does not exist. Is it exclusive for MonoBehaviours?

Any help is appreciated :smiley:


You can Instantiate from anywhere but due to inheritance Instantiate requires no preamble inside a mono behaviour. In your own class you can Instantiate like this:

      var instance  = Object.Instantiate(somePrefab);

MonoBehaviours have the advantage of being serialized automatically by the system as are references to them on other MonoBehaviour classes that you might define in the scene view. They are pretty heavy, however, they also support all of the functions that indicate events within the Unity system such as Update, OnGUI and network connections.

The other “downside” of MonoBehaviours is that they must be attached to a GameObject, you can’t just create one - you have to use GameObject.AddComponent which means they really are associated with a physical presence in your game world - that’s often what you want, but if you are looking to describe some more abstract concept you’d be better off with normal classes.

Mono - Awake(), Start(), Update(), etc and attached to GameObject. Classes that doesn’t derive from Mono - not.