D
D
Dmitry Korolev2017-07-02 14:28:51
C++ / C#
Dmitry Korolev, 2017-07-02 14:28:51

Why is the class constructor not supported in the unit?

Why is the constructor not supported in the unit? Are inheritance and polymorphism supported?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2017-07-02
@adressmoeistranici

Everything is supported. And the constructor, and inheritance, and polymorphism. The current for MonoBehaviour is slightly different rules - there is Start / Awake.

E
Espleth, 2017-07-02
@Espleth

For classes that inherit from MonoBehaviour, it's best not to use a constructor. First, it will also be called in the inspector before the game starts. Secondly, after starting it will be called twice, I don’t know what this is connected with, but that’s not the point. As you have already been told, you need to use Start / Awake. And to create heirs of the MonoBehaviour class, use AddComponent to "attach" to an object and Instantiate to create objects. On their own, without being used in the scene, these classes should not exist.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question