unity monobehaviour constructor function和SerializationCallbackReceiver对应

https://answers.unity.com/questions/862032/c-constructor-in-monobehaviour.html

 

See, serialization of the objects in the scene (and the scripts on them) happens a lot; whenever you save, whenever you press play, a lot of times. Instantiation of new objects, and thus calls to the constructor, probably happens as a part of that process. So if you say create a new gameobject as a part of your constructor, you'd be seeing that gameobject being added to your scene at different points when you didn't expect the constructor to be called.

 

在monobehaviour的class内使用construction function是不安全的。不推荐使用。

posted @ 2023-01-31 19:30  sun_dust_shadow  阅读(18)  评论(0编辑  收藏  举报