Unity3d common event execution sequence

Test sequence result: Awake -> OnEnable -> Start -> FixedUpdate -> Update -> LateUpdate -> OnGUI

1. Create a new TestOrder.cs script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestOrder: MonoBehaviour
{
    int index = 0;
    void Start()
    {
        index++;
        print("Start: " + index);
    }
    bool Updated = false;
    void Update()
    {
        if (Updated)
            return;
        Updated = true;
        index++;
        print("Update: " + index);
    }
    bool OnEnabled = false;
    private void OnEnable()
    {
        if (OnEnabled)
            return;
        OnEnabled = true;
        index++;
        print("OnEnable: " + index);
    }
    bool Awaked = false;
    private void Awake()
    {
        if (Awaked)
            return;
        Awaked = true;
        index++;
        print("Awake: " + index);
    }
    bool FixedUpdated = false;
    private void FixedUpdate()
    {
        if (FixedUpdated)
            return;
        FixedUpdated = true;
        index++;
        print("FixedUpdate: " + index);
    }
    bool LateUpdated = false;
    private void LateUpdate()
    {
        if (LateUpdated)
            return;
        LateUpdated = true;
        index++;
        print("LateUpdate: " + index);
    }
    bool OnGUIed = false;
    private void OnGUI()
    {
        if (OnGUIed)
            return;
        OnGUIed = true;
        index++;
        print("OnGUI: " + index);
    }
}

2. Drag and drop to Camera, and run the result (the result of testing 1000 sets of data has not changed, the order of execution should be able to rule out contingency)

 

Guess you like

Origin blog.csdn.net/zhunju0089/article/details/103585991