LogoLogo
VIVERSESupportBlogDiscord
  • Creator Tools
  • Polygon Streaming
  • Introduction to Creator Tools
  • Publishing with Your VIVERSE Account
  • Optimization
  • World Decoration
    • Edit Mode
    • Supported Media & Settings
    • Creating From Templates
      • Pet Rescue Template Project
  • PlayCanvas SDK
    • PlayCanvas Extension Setup
    • Publishing to VIVERSE
    • Scene Settings
    • No Code Tools
      • Sample Project
      • Quests
      • Trigger & Action
        • Event Listeners
        • Entity Enabling & Disabling
        • Entity Collision Enabling & Disabling
        • Entity Physics
        • Avatar Teleport & Checkpoint
        • Animation & Sound
        • Asset Management
      • Media
        • Polygon Streaming
        • Images
        • Video
        • Audio
      • Pick and Throw
      • Networked
      • Seat
      • GPU Mesh Instancing
    • Custom Code
      • Connecting No-Code Events to Custom Scripts
      • Introduction to MJS
      • Camera Management: Settings and Switching
      • Custom Loading Screens
      • Change Avatars Programatically
    • Examples
      • Create Your First PlayCanvas Project
      • SHADEART | Custom Shader
      • WITHIN | A Generative Audiovisual Maze
      • First Person Shooter with Destruction
  • Unity SDK
    • Porting from Unity to PlayCanvas
Powered by GitBook
LogoLogo

Important Links

  • COOKIE POLICY
  • TERMS OF SERVICE
  • PRIVACY POLICY
  • VIVERSE PARTNERS

Socials

  • X / Twitter
  • LinkedIn
  • Instagram

© 2025 HTC CORPORATION

On this page

Was this helpful?

Edit on GitHub
Export as PDF
  1. PlayCanvas SDK
  2. Custom Code

Change Avatars Programatically

Control how users see and express themselves with the .changeAvatar() method on LocalPlayer

PreviousCustom Loading ScreensNextExamples

Last updated 1 day ago

Was this helpful?

If you don't want to use default VIVERSE avatars for your world, the PlayCanvas SDK features a simple method to swap to any .vrm avatar asset in your project.

, import the into your .mjs script, which has a of type LocalPlayer, which in turn has a .

import { Script, Asset } from "playcanvas";
import { PlayerService } from "../@viverse/create-sdk.mjs";

export class VvSwitchAvatars extends Script {
  static scriptName = "vvSwitchAvatars";

  /**
   * @attribute
   * @type {Asset}
   */
  vrmAsset = null;

  initialize() {
    this.playerService = new PlayerService();
    this.playerService.localPlayer.changeAvatar(this.vrmAsset);
  }
}

Because vrmAsset is defined as an attribute of type Asset, we can then select which asset to use directly in the PlayCanvas editor once the script is added to an entity.

NOTE: this script asset must be placed in /scripts or another subfolder, since it assumes the VIVERSE SDK is one level up, located at: "../@viverse/create-sdk.mjs" - or you can alter this import path as needed. For more information on how .mjs scripts and imports work, see .

When we publish to VIVERSE and load the experience, the .vrm is loaded immediately. Avatar switching for the local player is possible at any point during runtime and can be triggered with UI, trigger colliders, or with any other programmatic callback. Reference Code:

Per the API docs
PlayerService
localPlayer property
.changeAvatar() method
Introduction to MJS
PlayCanvas minimal reproduction project
Live demo