Studio GuideWorld SDK Guide
Log In
World SDK Guide

ZEPETO Player

The ZepetoPlayer serves as the unit instance for the ZEPETO character in a multiplayer world. It represents both the player you directly control and other players in the scene.

In this guide, we'll explore how to utilize the ZEPETO Player's API to display information about the Local Player you're operating.


Zepeto Player API

If you're interested in the ZepetoPlayer API, refer to the documentation:

📘


Basic Local Player Usage Example

Checking the Loading Status of the Local Player

Make use of the OnAddedLocalPlayer() callback to verify if the Local Player has loaded.

Here's a sample code illustrating this:

import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
import { SpawnInfo, ZepetoPlayers, LocalPlayer, ZepetoCharacter } from 'ZEPETO.Character.Controller';
import { WorldService } from 'ZEPETO.World';

export default class LocalPlayerLoader extends ZepetoScriptBehaviour {

    private _localPlayer: LocalPlayer;
    
    Awake() {
        if(!this._localPlayer) {
            console.log("Local Player has not finished loading.");
        }
    }

    Start() {
        ZepetoPlayers.instance.CreatePlayerWithUserId(WorldService.userId, new SpawnInfo(), true);
        ZepetoPlayers.instance.OnAddedLocalPlayer.AddListener(() => {
            this._localPlayer = ZepetoPlayers.instance.LocalPlayer;
            console.log("Local Player has finished loading.");
        });
    }
}

  • Script Explanation:
    • Initially, the this._localPlayer is undeclared, meaning it has a null value. You create the local player based on the logged-in user ID using
    • ZepetoPlayers.instance.CreatePlayerWithUserId(). Once the local player has finished loading, the OnAddedLocalPlayer() callback assigns value to this._localPlayer.
    • This method allows you to load the local player and verify its loading status.
LocalPlayer가 로딩 되기 전과 후에 찍히는 콘솔 로그 메세지

Console Logs before and after LocalPlayer Loading


Displaying Local Player Information

Below is an example of how to print the zepeto ID, user ID, and name of the loaded local player to the console log.

Please note that in the sample code provided, ZepetoPlayers.instance.CreatePlayerWithUserId() is not explicitly added.

import { ZepetoScriptBehaviour } from 'ZEPETO.Script'
import {LocalPlayer, ZepetoPlayers} from "ZEPETO.Character.Controller";

export default class LocalPlayerInfo extends ZepetoScriptBehaviour {

    private _localPlayer: LocalPlayer;
    
    Start() {
        ZepetoPlayers.instance.OnAddedLocalPlayer.AddListener(() => {
            this._localPlayer = ZepetoPlayers.instance.LocalPlayer;
            console.log(`Is LocalPlayer : ${this._localPlayer.zepetoPlayer.isLocalPlayer}`);
            console.log(`User ID : ${this._localPlayer.zepetoPlayer.userId}`);
            console.log(`Name : ${this._localPlayer.zepetoPlayer.name}`);
        });
    }

}