Skip to content

Experience ​

Properties ​

currentScene read-only ​

  • Type: Scene
  • The current scene

environment read-only ​

  • Type: Environment
  • Environment information (platform, OS version, locale)

language ​

  • Type: any
  • The language the experience's texts show in, as a BCP 47 code such as "de", or undefined when the experience has no translations.

Example:

javascript
const price = new Intl.NumberFormat(experience.language, { style: 'currency', currency: 'EUR' }).format(4.5);
experience.language = 'de';

sharedActivity read-only ​

  • Type: SharedActivity
  • Shared activity state (SharePlay, WebSocket, or other shared session protocols)

Methods ​

closeScreen() ​

javascript
closeScreen(name?: string): Promise<void>

Close one of the experience's screens, as Close Screen does.

The screen leaves with its own Removal Animation. Without a name, closes the screen whose event ran this script.

Example:

javascript
// On a screen's Close button: close the screen this script belongs to.
await experience.closeScreen();

Parameters:

  • name (string) (optional) - The screen's name, as shown in the Screens section.

Returns: Promise<void>

getVariable() ​

javascript
getVariable(id: string): any

Get an experience-scoped variable

Example:

javascript
var count = experience.getVariable('visitCount');
var name = experience.getVariable('userName');

Parameters:

  • id (string) - Variable identifier

Returns: any

localize() ​

javascript
localize(key: string, values: any): string

Returns a shared text in the experience's language, with each ${name} replaced by values.name.

Example:

javascript
// A shared text named "Score" reads "You found ${count} of ${total}".
label.text = experience.localize('Score', { count: 3, total: 5 });

Parameters:

  • key (string) - The shared text's name, as shown in Translations.
  • values (any) - Optional object whose properties fill the text's placeholders.

Returns: string

openScreen() ​

javascript
openScreen(name: string): Promise<ObjectEntity>

Show one of the experience's screens, made in the editor's Screens section, as Open Screen does.

The screen appears with its own Reveal Animation, on top of anything already showing. Opening a screen that is already open does nothing and resolves with it.

Example:

javascript
// Open a details screen and fill in its title.
const details = await experience.openScreen('Details');
details.representation.findView({ name: 'Title' }).setProperty('text', 'House 25');

Parameters:

  • name (string) - The screen's name, as shown in the Screens section.

Returns: Promise<ObjectEntity>

setVariable() ​

javascript
setVariable(id: string, value: any, options: any): void

Set an experience-scoped variable (persists across scene transitions)

Example:

javascript
experience.setVariable('visitCount', 3);
experience.setVariable('userName', 'Alice');
experience.setVariable('lastPosition', Vector3(0, 1, 0), { type: 'vector3' });

Parameters:

  • id (string) - Variable identifier
  • value (any) - Value to store (number, string, boolean, Vector3, Color, etc.)
  • options (any) - Optional type hint { type: "vector3" | "color" | ... }

Returns: void

transitionToScene() ​

javascript
transitionToScene(id: string): void

Transition to another scene

Example:

javascript
experience.transitionToScene('chapter-2');

Parameters:

  • id (string) - Scene identifier

Returns: void