Awake() and Start()

后端 未结 4 956
北荒
北荒 2020-12-29 01:02

I see that we can initialize Variable in Awake() or Start() and Awake() will be called before Start().

When shou

4条回答
  •  旧巷少年郎
    2020-12-29 01:21

    This topic is well described in the official docmentation (Awake and Start).

    This section describes why you might need two functions:

    The Awake function is called on all objects in the scene before any object's Start function is called. This fact is useful in cases where object A's initialisation code needs to rely on object B's already being initialised; B's initialisation should be done in Awake while A's should be done in Start.

    The difference between Awake and Start is that Start is called only when a script is enabled.

    These two functions are called before the first Update method and there is no performance difference between them. I would say that Awake is used to initialize all objects (like a constructor), and Start is used to link the objects or do something before a game starts.

提交回复
热议问题