Studio GuideWorld SDK Guide
Log In

Event Functions

The Unity game engine offers regular update events that you can add logic to the lifecycle (creation, updates in every frame, termination) or the events (UI events, collision detection) of an object (or GameObject) within the script.

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.

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.

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.


Unity Event Functions


Order of Execution for Event Functions