Studio GuideWorld SDK Guide
Log In

Event Functions

Event Functions are special functions automatically called during the Life Cycle of a GameObject or component in the Unity engine, Therefore, they are also referred to as Lifecycle Event Functions.

Event Functions are automatically called by the Unity engine at specific timings.

Event Functions are special functions automatically called during the Life Cycle of a GameObject or component in the Unity engine, hence they are also referred to as Lifecycle Event Functions.

ZEPETO Script Lifecycle Flowchart

ZEPETO Script Lifecycle Flowchart

Initialization events

  • You can use an initialization event to call the initialization code before an update.
  • The Start function is called before any physics update and before the first frame, while the Awake function is called for each object in the scene when calling up a scene.
  • Start and Awake functions for various objects are called in random order, but all Awake calls are finished before Start is called.
  • This means that the Start function can use other initializations previously carried out in the Awake function.

Regular update events

  • Regular updates refers to all updates called every frame.
  • They change the position, state, and behavior of objects before each frame is rendered.
  • ZEPETOScript provides a guideline for processing the computation in the Update function.

Physics events

  • Physics events call event functions through a script added in the GameObject.
  • The OnCollisionEnter, OnCollisionStay, and OnCollisionExit functions are called as contact is made, held, and broken.
  • The OnTriggerEnter, OnTriggerStay and OnTriggerExit functions are called when an object collider is configured as a trigger (i.e. a collider that does not react physically to collisions but simply detects them instead).
  • Such functions may be called several times in succession if multiple contacts are detected during the physics update, and thus parameters are sent to the function that provides details of the collision (position, identity of the object).

GUI events

  • ZEPETOScript supports events that render GUI controls and reacts to clicks from the elements. They work differently from normal frame updates, so UI related logic should be placed in the OnGUI function.

Mouse Events

  • In ZEPETOScript, events that respond to mouse interactions are supported.
  • However, mouse events require a Collider or Collider2D to be present on the relevant GameObject, and they are only triggered when that Collider is clicked with the mouse.
  • OnMouseDown() is called when the user clicks the mouse button.
  • OnMouseUp() is called when the user releases the mouse button.
  • OnMouseOver() is called every frame while the mouse cursor is over the Collider or Collider2D of the GameObject.

Termination Events

  • Termination events are called in all activated objects in a scene.
  • The OnDisable function is called when a given object is disabled or is inactive, and OnApplicationQuit is called on all GameObjects before the application closes.


Unity Event Functions

All the event functions inherently supported by ZEPETOScript are listed in the sample code below.

import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
import { Collider, Collider2D, Collision, Collision2D } from 'UnityEngine';

export default class SampleMonoBehaviourLifeCycle extends ZepetoScriptBehaviour {

    Awake() {
    OnEnable() {
    Start() {

    Update() {
    FixedUpdate() {
    LateUpdate() {

    OnDisable() {
    OnDestroy() {

    OnTriggerEnter(coll: Collider) {
        console.log(`OnTriggerEnter ${}.`);
    OnTriggerExit(coll: Collider) {
        console.log(`OnTriggerExit ${}.`);
    OnTriggerStay(coll: Collider) {
        console.log(`OnTriggerStay ${}.`);

    OnTriggerEnter2D(coll: Collider2D) {
        console.log(`OnTriggerEnter2D ${}.`);
    OnTriggerExit2D(coll: Collider2D) {
        console.log(`OnTriggerExit2D ${}.`);
    OnTriggerStay2D(coll: Collider2D) {
        console.log(`OnTriggerStay2D ${}.`);

    OnCollisionEnter(coll: Collision) {
        console.log(`OnCollisionEnter ${}.`);
    OnCollisionExit(coll: Collision) {
        console.log(`OnCollisionExit ${}.`);
    OnCollisionStay(coll: Collision) {
        console.log(`OnCollisionStay ${}.`);

    OnCollisionEnter2D(coll: Collision2D) {
        console.log(`OnCollisionEnter2D ${}.`);
    OnCollisionExit2D(coll: Collision2D) {
        console.log(`OnCollisionExit2D ${}.`);
    OnCollisionStay2D(coll: Collision2D) {
        console.log(`OnCollisionStay2D ${}.`);

    OnGUI() {
    OnMouseDown() {
    OnMouseDrag() {
    OnMouseUp() {
    OnMouseEnter() {
    OnMouseExit() {
    OnMouseOver() {
    OnMouseUpAsButton() {

    OnAnimatorIK(layerIndex: number) {
        console.log(`OnAnimatorIK ${layerIndex}.`);

    OnApplicationFocus() {
    OnApplicationPause() {
    OnApplicationQuit() {


Check out the test code output screen below.

You can learn more about the Unity event functions that ZEPETOScript offers by clicking the links below.


Order of Execution for Event Functions