테스트용 객체
public class LifecycleTest : MonoBehaviour
{
public GameObject LTest; //동일 클래스가 들어있는 프리팹
void Start()
{
Debug.Log($"Start - {Time.realtimeSinceStartup:F6}s (Frame: {Time.frameCount})");
Instantiate(LTest); //스타트 함수에 자기와 동일한 객체 생성
}
private void Update()
{
Debug.Log($"Update - {Time.realtimeSinceStartup:F6}s (Frame: {Time.frameCount})");
}
private void FixedUpdate()
{
Debug.Log($"FixedUpdate - {Time.realtimeSinceStartup:F6}s (Frame: {Time.frameCount})");
}
private void LateUpdate()
{
Debug.Log($"LateUpdate - {Time.realtimeSinceStartup:F6}s (Frame: {Time.frameCount})");
}
}
모든 프레임의 Start 호출 타이밍 상세 분석
프레임별 타이밍 분포
Frame 1 (총 7개):
- FrameStart: 1개
- After FixedUpdate: 2개
- During Update: 2개
- During LateUpdate: 2개
Frame 2 (총 7개):
- FrameStart: 1개
- After FixedUpdate: 2개
- During Update: 2개
- During LateUpdate: 2개
Frame 3 (총 13개): ⚡ 피크
- FrameStart: 1개
- After FixedUpdate: 8개 (최대)
- During Update: 2개
- During LateUpdate: 2개
Frame 4 (총 11개):
- FrameStart: 1개
- After FixedUpdate: 6개
- During Update: 2개
- During LateUpdate: 2개
Frame 5 (총 9개):
- FrameStart: 1개
- After FixedUpdate: 4개
- During Update: 2개
- During LateUpdate: 2개
Frame 6 (총 11개):
- FrameStart: 1개
- After FixedUpdate: 6개
- During Update: 2개
- During LateUpdate: 2개
Frame 7-9 (각 7개): 안정화
- FrameStart: 1개
- After FixedUpdate: 2개
- During Update: 2개
- During LateUpdate: 2개
Frame 10 (총 9개):
- FrameStart: 1개
- After FixedUpdate: 4개
- During Update: 2개
- During LateUpdate: 2개
Frame 11-13 (각 7개): 안정화
- FrameStart: 1개
- After FixedUpdate: 2개
- During Update: 2개
- During LateUpdate: 2개
Frame 14 (총 11개):
- FrameStart: 1개
- After FixedUpdate: 6개
- During Update: 2개
- During LateUpdate: 2개
Frame 15 (총 9개):
- FrameStart: 1개
- After FixedUpdate: 4개
- During Update: 2개
- During LateUpdate: 2개
📊 핵심 패턴 발견
- 고정 패턴 (모든 프레임 공통)
- FrameStart: 항상 정확히 1개
- During Update: 항상 정확히 2개
- During LateUpdate: 항상 정확히 2개
- 가변 패턴 (After FixedUpdate)
- 최소: 2개 (안정화된 프레임)
- 최대: 8개 (Frame 3)
- 이 부분이 전체 Start 호출 수의 변동을 결정
- 항상 짝수갯수가 호출됨
해석결론 : 모종의 이유로 프레임시작에 1개, Update 도중 2개, LateUpdate 도중 2개의 start슬롯이 있음. 이 슬롯이 다 차면 그 뒤로 FixedUpdate 다음에 호출됨. 짝수로 호출되는데 홀수일 경우 다음 프레임으로 가는 것으로 보임
최종결론 : Start함수는 FixedUpdate 후 Update전에 호출되는 주기함수이지만 1프레임당 5번의 예외호출이 있음. 이는 유니티 자체 설계미스로 보여짐. Start를 깔끔한 주기함수라 생각하고 개발한다면 타이밍이슈가 생길 수 밖에 없음.
추가실험 후 추가결론 : 예외 호출이아님. 타이밍에 의한 고정 패턴이었을 뿐이었. Star함수는 주기가 없는 함수임. 어느 타이밍에도 호출될 수 있음. Awake다음에 호출되고 그 뒤 실행되는 업데이트는 어떤 업데이트일지 모름.
'소프트웨어 공학 > 코딩' 카테고리의 다른 글
| Unity] Awake, OnEnable 타이밍 간단내용 (3) | 2025.07.25 |
|---|---|
| Unity] Start함수 정밀 분석 완료 (0) | 2025.07.25 |
| Unity] 라이프사이클 (Awake, OnEnable, Start)에 대한 실험결과 (1) | 2025.07.25 |
| CS] 메모리, 배열vs리스트, 커널, 코어와스레드, 멀티스레딩과 비동기 (2) | 2025.07.23 |
| 유니티] 어셈블리 정의 asmdef파일 (1) | 2025.06.16 |