Event listeners

There are several events that the scene can subscribe to, to know the actions of the player while in or near the scene.

For button and click events performed by the player, see Button events.

Player changes camera mode

When the player changes the camera mode between 1st and 3rd person in or near your scene, this creates an event you can listen to.

onCameraModeChangedObservable.add(({ cameraMode }) => {
  log("Camera mode changed:", cameraMode)

The value of the returned property can either be CameraMode.FirstPerson or CameraMode.ThirdPerson.

This event informs changes to the camera mode once the player is already in or near your scene. To know the initial camera mode of the player when first arriving to your scene, check the value of Camera.instance.cameraMode. See User Data.

// intitial camera mode
log("Camera mode: ", Camera.instance.cameraMode)

// check for changes
onCameraModeChangedObservable.add(({ cameraMode }) => {
  log("Camera mode changed:", cameraMode)

Player plays animation

Whenever the player plays an emote (dance, clap, wave, etc), you can detect this event.

onPlayerExpressionObservable.add(({ expressionId }) => {
  log("Expression: ", expressionId)

The event includes the following information:

  • expressionId: Name of the emote performed (ie: wave, clap, kiss)

Note: This event is triggered any time the player makes an emote and the scene is loaded. The player could be standing in a nearby scene when this happens.

Player goes idle

Whenever the player is inactive for a full minute, without interacting with any input being picked up by the Decentraland explorer, we can consider the player to be idle. Whenever this happens, it creates an event that you can listen to.

onIdleStateChangedObservable.add(({ isIdle }) => {
  log("Idle State change: ", isIdle)

The isIdle property is a boolean value that is true when the player enters the idle mode and false when the player leaves the idle mode.

This event is especially useful for multiplayer scenes, when you might want to disconnect from the server players who are likely away from the machine or left Decentraland in a tab in the background.

Note: The idle state is inferred based on the player not using the keyboard or mouse for a full minute. This can of course produce false positives, for example a player might be watching other players interact or watching a video stream, standing still but fully engaged. Be mindful of these corner cases and what the experience is like for a player who stands still for a while.

Scene finished loading

When the scene finishes loading, the onSceneReadyObservable gets called. This works both if the player loads straight into the scene, or if the player walks up to the scene from somewhere else. When all of the content in the scene has finished its initial load, including heavy models, etc, this event is called.

onSceneReadyObservable.add(() => {

Player starts/ends the tutorial

When a new player first enters Decentraland for the fist time, they go through a brief tutorial that shows the basic movements and UI elements. Typically players will experience this on Genesis Plaza, but a new player that enters a specific scene from an event as their first time in Decentraland will experience a shortened version of that tutorial wherever they are.

This tutorial includes some music, that could clash with the music of the scene that the player is currently on, so it’s recommended to stop any background music in case the player is going through the tutorial.

import { tutorialEnableObservable } from 'src/modules/tutorialHandler'

tutorialEnableObservable.add((tutorialEnabled) => {
  if (tutorialEnabled) {
	log("Player started tutorial")
    backgroundMusicSource.playing = false
  } else {
    log("Player finished tutorial")
    backgroundMusicSource.playing = true

Note: This event only occurs when the player starts or ends the tutorial. It doesn’t get called at all in case the player has already experienced the tutorial in a prior session or scene.