- Home /
How do I use the "new" Keyword and MonoBehaviour methods
I am making a map Generation System that uses "Points" which store data and for debug use also needs to manipulate GameObjects. In the main Generation for these "Points" I make "Points" using a Constructor and the keyword new but this can not be used with MonoBehaviours and making all of the points GameObjects would be very memory intensive and pointless considering since they are only as dataBases and Debug items. Any way to stil use MonoBehaviour methods such as Update or Start and still use constructors?
Answer by gregzo · Jul 26, 2013 at 07:14 AM
GameObject.AddComponent will effectively instantiate your Monobehaviour and call it's Awake() and Start() methods ( as well as OnDestroy, OnEnable, OnDisable etc... ).
If you need to initialize the component somehow, use a public Init method.
No need to have one GameObject per component, they can pile up on one.
But I suspect you don't really need Start or Awake on each of your Points : Point objects could be managed by a PointManager, which does inherit from Monobehaviour. Points can be dumb...
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Constructor giving nullreference error 1 Answer
Prior Knowledge 0 Answers
Make a game in C# 0 Answers
How to start in Unity? 1 Answer