- Home /
Question by
Mactarvish · Aug 02, 2019 at 06:59 PM ·
initialization
How to initialize an instance with parameters?,How to pass parameters when initializing instance without "new"?
Hi, I'm trying to create an instance, passing parameters to them so as to initialize them with some external information. I tried to write a custom constructor function with parameters and use "new" to call the constructor function to create the instance, but I was told that unity doesn't allow programmer using new to create manobehaviours. Are there any other way to do this? Thanks in advance.
Comment
Answer by Casiell · Aug 02, 2019 at 07:02 PM
If you are talking about a MonoBehaviour then you have to create a separate method (Init or something) and you have to remember to call it every time you instantiate this object. You can tinker with a method that both instantiates and calls your initialize method if you want