Life Cycle Callbacks

    The life cycle callback functions currently provided to users mainly include (order by life cycle trigger):

    • onLoad()
    • onEnable()
    • update()
    • lateUpdate()
    • onDisable()
    • onDestroy()

    In the initialization phase of the component script, the onLoad() callback function is available. The onLoad() callback will be triggered when the node is activated for the first time, such as when the scene is loaded or the node is activated. In the stage, it is guaranteed that you can get other nodes in the scene and the resource data associated with the nodes. onLoad() will always be executed before any start method is called, which can be used to arrange the initialization sequence of the script. Usually, some initialization related operations are performed in the onLoad() stage. Example:

    onEnable()

    The start() callback function will be triggered before the first activation of the component, that is, before the first execution of . start() is usually used to initialize some intermediate state data. These data may change during update and are frequently enabled and disabled. Example:

    update()

    A key point of game development is to update the behavior, state and orientation of objects before each frame of rendering. These update operations are usually placed in the update() callback. Example:

    onDisable()

    When the enabled property of the component changes from true to false, or the node’s active property changes from true to false, the onDisable() callback will be activated.

    When the component or the node where it calls , the onDestroy() callback will be called, and the component will be recycled when the frame ends.