[완] Scene의 게임오브젝트들의 인스턴스화 되는 시점은 어떻게 결정 되는가?

Unity3D/Problems 2013. 1. 3. 14:08
반응형

하나의 씬에 수많은 오브젝트들이 있다고 생각하자. (동적으로 생성되는 오브젝트는 제외)

각 오브젝트들에는 어싸인되어 있는 스크립트들이 있기도 하고 없는것도 있다.

이 스크립트들은 오브젝트가 인스턴스화 되고난뒤 Awake함수가 호출된다.

그럼 어느 오브젝트가 젤 먼저 인스턴스화 되는것인가?


레퍼런스에 의하면 오브젝트의 인스턴스화 되고 Awake함수가 호출되는 시기는 일정하지 않다고 한다.


Awake is used to initialize any variables or game state before the game starts. Awake is called only once during the lifetime of the script instance. Awake is called after all objects are initialized so you can safely speak to other objects or query them using eg. GameObject.FindWithTag. Each GameObject's Awake is called in a random order between objects. Because of this, you should use Awake to set up references between scripts, and use Start to pass any information back and forth. Awake is always called before any Start functions. This allows you to order initialization of scripts. Awake can not act as a coroutine.


테스트해본결과 나중에 만들어진 오브젝트의 스크립트 Awake함수가 가장 먼저 실행되는걸 확인했다.

이것이 맞는 것일까...






http://docs.unity3d.com/Documentation/Manual/ExecutionOrder.html






결론: 유니티는 컴포넌트 기반으로 돌아간다 때문에 메인클래스가 존재 하지 않는것. 만약 궂이 실행되는 스크립트의 순서를 지정하고 싶다면 

를 설정하여 사용할수있다. 또한 싱글턴 클래스를 만들어 프로젝트내 절차를 컨트롤 하는 방법도 있을것이다.




반응형
: