반응형

처음 호출은 Awake, OnEnable, Start 이 순으로 호출이 되는데

Object가 Enable = true (활성화 ) 될 때마다 OnEnable() 이 호출 된다



If a script is attached to more than one gameObject, will Start() & Awake() run more than once?

The same script. Different gameObjects disabled at runtime. Enabled at different time periods throughout the game.

Will Start() & Awake() run for each gameObject becoming enabled?

Or do I need to use OnEnable()?

2 Replies

 · Add your reply
avatar image
1

Answer by Bodrp 

Start() and Awake() will be called when the component becomes active for the first time only. They will act on their own instance of the component (since they are not static methods). OnEnable() gets called everytime the component becomes active. By "acting on their own instance" I mean that for every instance of the component, they will be called and will have access to their instance's attributes, whatever may be their access level.

Awake() will be called first, then OnEnable(), then Start(). If multiple components are activated at the same time, Awake() and OnEnable() methods will be called jointly for each instance. When that's done, each instance's Start() method will be called.

For more information about the methods Unity calls with reflection on your components, you can refer to the execution order page of the manual.



http://answers.unity3d.com/questions/1346838/if-a-script-is-attached-to-more-than-one-gameobjec.html

반응형

+ Recent posts