APIGENERAL
SPACES OVERVIEW
Introduction
Spaces Changelog
DESIGNING SPACES

World Creation

Overview
Creating Models
Importing Objects
Adjusting Looks
Recommended external tools

World Constraints

Scene Limitations
Health Monitor

Using Plugins

Media: Audio
Places
PLUGINS IN SPACES

Build & Publish

Overview
Publishing
Support & Feedback
Examples

Plugin Guides

Creating a Plugin
Creating a Component
Custom Avatars

Plugin Core API

Globals
App
Audio
Menus
Messages
Objects
Paths
Textures
User
World

Plugin Hooks

Hooks
General Hooks
Media Playback Hooks
Change LogForum

User

Allows access to user information.

When extending BasePlugin, these functions can be accessed via this.user.*

When extending BaseComponent, these functions can be accessed via this.plugin.user.*

Functions

getID() : Promise<string>

Returns the identifier of the user.

Example

const id = await this.user.getID()
console.log(id) // => 'user-id'

getDisplayName() : Promise<string>

Returns the display name of the user.

Example

const name = await this.user.getDisplayName()
console.log(name) // => 'John Doe'

isAdmin() : Promise<boolean>

Returns true if the user is an admin in this space and false otherwise. Admins are able to edit objects.

Example

const isAdmin = await this.user.isAdmin()
console.log(isAdmin) // => true

isMuted() : Promise<boolean>

Returns true if the user is muted and false if their microphone is 'on air'.

Example

const isMuted = await this.user.isMuted()
console.log(isMuted) // => true

Also see the core.user.audio.mute-change hook to receive a callback when the microphone mute state changes.

getInitialPosition() : Promise<Vector3>

Returns the position that the user will be in when they enter the space, in the form: { x: number, y: number, z: number }.

Example

const position = await this.user.getInitialPosition()
console.log(position) // => { x: 1, y: 0, z: 2 }

getPosition() : Promise<Vector3>

Returns the position of the user, in the form: { x: number, y: number, z: number }.

Example

const position = await this.user.getPosition()
console.log(position) // => { x: 2, y: 0, z: 3 }

setPosition(x: number, y: number, z: number, instant = false, keepFollow = true) : Promise<void>

Sets the position of the user.

FieldTypeDescriptionExample
xnumberNew x position2
ynumberNew y position (height)0
znumberNew z position (depth)3
instantbooleantrue to immediately move avatar, false to glide to position. Default is falsefalse
keepFollowbooleantrue to keep following the object that the user is currently following, false to stop following. Default is truetrue

Example

await this.user.setPosition(2, 0, 3)

getOrientation(deg = false) : Promise<number>

Returns the orientation of the user in degrees, if deg === true, or radians, if deg === false. Default is in radians.

FieldTypeDescriptionExample
degbooleantrue to use degrees, false to use radiansfalse

Example

const orientation = await this.user.getOrientation()
console.log(orientation) // => 1.5708

setOrientation(orient: number, deg = false) : void

Sets the orientation of the user in degrees, if deg === true, or radians, if deg === false. Default is in radians.

FieldTypeDescriptionExample
orientnumberNew orientation1.5708 (if deg === false)
degbooleantrue to use degrees, false to use radiansfalse

Example

this.user.setOrientation(1.5708)

getTilt(deg = false): Promise<number>

Returns the tilt value of the user in degrees, if deg === true, or radians, if deg === false. Default is in radians.

FieldTypeDescriptionExample
degbooleantrue to use degrees, false to use radiansfalse

Example

const tilt = await this.user.getTilt()
console.log(tilt) // => 0.0115

setTilt(tilt: number, deg = false) : void

Sets the tilt value of the user in degrees, if deg === true, or radians, if deg === false. Default is in radians.

FieldTypeDescriptionExample
tiltnumberNew tilt0.0115 (if deg === false)
degbooleantrue to use degrees, false to use radiansfalse

Example

this.user.setTilt(0.0115)

getZoom() : Promise<number>

Returns the zoom level of the user.

Example

const zoom = await this.user.getZoom()
console.log(zoom) // => 12

setZoom(zoom: number) : Promise<boolean>

Sets the zoom level of the user.

Final zoom value is clamped between the "Minimum Zoom Distance" and "Maximum Zoom Distance" settings found in the Editor > World tab.

FieldTypeDescriptionExample
zoomnumberNew zoom level12

Example

const success = await this.user.setZoom(12)
console.log(success) // => true

getViewMode() : Promise<string>

Returns the view mode of the user, which will be one of: "swivel", "advanced" or "first-person".

Example

const viewMode = await this.user.getViewMode()
console.log(viewMode) // => "advanced"

setViewMode(mode: string, options?: ViewModeOptions) : Promise<boolean>

Sets the view mode of the user, which should be one of: "swivel", "advanced" or "first-person", as well as configuration options if provided.

FieldTypeDescriptionExample
modestringNew view mode"advanced"
optionsobjectOptions relating to the view mode{ fullscreen: true, pointerLock: true }

Properties available for the options parameter

PropertyTypeDescriptionExample
configobjectConfiguration options for the given view mode. Available fields are dependent on the given view mode{}
fullscreenbooleantrue to enable fullscreen mode, false to exit fullscreen modetrue
pointerLockbooleantrue to request pointer lock (only supported in "first-person" view mode), false to exit pointer locktrue

Example

const success = await this.user.setViewMode("advanced")
console.log(success) // => true
// OR
const success = await this.user.setViewMode(
	"first-person",
	{
		pointerLock: true,
		fullscreen: true
	}
)
console.log(success) // => true

getFollow() : Promise<boolean>

Returns true if the user is following another user or object, false otherwise.

Example

const isFollowing = await this.user.getFollow()
console.log(isFollowing) // => false

setFollow(id: string) : void

Sets the user to follow the object with a matching identifier. Can be an object or another user.

FieldTypeDescriptionExample
idstringIdentifier of the user, or object, to follow'042ed071-649c-4601-9a30-669a59c9e1ee'

Example

this.user.setFollow('042ed071-649c-4601-9a30-669a59c9e1ee')

releaseFollow() : void

Stops the user from following the user or object that they are currently following, if any.

Example

this.user.releaseFollow()

getProperty(userID: string, property: string) : Promise<any>

Returns a property that had been assigned to the specified user by calling user.setProperties() from this plugin. Leave userID blank to get the property on the current user.

FieldTypeDescriptionExample
userIDstringIdentifier of the user to get a property value for''
propertystringName of the property to retrieve'color'

Example

const color = await this.user.getProperty('', 'color')
console.log(color) // => '#2DCA8C'

getProperties(userID: string) : Promise<UserProps>

Returns all properties that had been assigned to the specified user by calling user.setProperties() from this plugin. Leave userID blank to get the property on the current user.

FieldTypeDescriptionExample
userIDstringIdentifier of the user to get all property values for''

Example

const props = await this.user.getProperties('')
console.log(props) // => { id: 'long-form-id:user-id', name: 'John Doe', user_id: 'user-id', role: 'presenter', color: '#2DCA8C' }

setProperties(newProps: UserProps) : Promise<void>

Sets properties for this user within the context of this plugin.

Properties will be merged in. Fields not specified will be left unchanged. Prefix property names with space: if you want the value to be specific to an individual space and not carry over into multiple spaces.

FieldTypeDescriptionExample
newPropsobjectNew property values to assign{ color: '#2DCA8C' }

Example

await this.user.setProperties({ color: '#2DCA8C' })

getNearbyUsers() : Promise<UserProps[]>

Returns a list of users who are within rendering range.

Each user has the form: { id: string, name: string, userID: string, role: string, distance: number }

Example

const nearbyUsers = await this.user.getNearbyUsers()
console.log(nearbyUsers) // => [{ id: 'long-form-id:user-id', name: 'John Doe', userID: 'user-id', role: 'presenter', distance: 0.5 }]

registerAvatar(props: AvatarProps) : Promise<void>

Registers a custom avatar that users can select in the Profile > Select Avatar menu. See Custom Avatars for more information. The props object can contain these fields:

FieldTypeExampleDescription
idstring'com.myplugin.myavatar'A unique ID representing this avatar.
namestring'My Avatar'The name of this avatar. This is displayed to the user in the Select Avatar popup.
typestring'humanoid'The type of skeleton. If "static" the avatar model will not be dynamically animated except for a simple rotation to face the direction the user is moving. Otherwise, this field represents the skeleton type of the avatar model. The app includes built-in animations for "humanoid" skeleton types, but you can also use your own skeleton type along with your own animations. See Custom Avatars for more info.
imageURLstring'./preview.jpg'A URL pointing to the preview image for this avatar. The preview image is displayed to the user in the Select Avatar popup.
propertiesobject{ url: '...' }Object properties for the avatar model. You can specify any object property fields. The object type defaults to 'model'.
heightnumber1.8The avatar's height. Default is 1.8 meters.
walkingSpeednumber2The avatar's movement speed while walking. Defaults to 2.
runningSpeednumber4The avatar's movement speed while running. Defaults to 4.
hookOnSetupstring'myplugin.onSetup'If specified, this hook will be called when the user selects the avatar. This gives your plugin the opportunity to modify avatar data, for example you could display an avatar customizer UI to the user and return updated data from the hook once the user completes the setup. You can also return null from the hook to cancel the avatar switch.

Example

await this.user.registerAvatar({
  id: 'com.myplugin.myavatar',
  name: 'My Avatar',
  type: 'humanoid',
  imageURL: this.paths.absolute('./preview.jpg'),
  properties: { url: '...' },
  height: 1.8,
  walkingSpeed: 2,
  runningSpeed: 4,
  hookOnSetup: 'myplugin.onSetup'
})

unregisterAvatar(id: string) : void

Removes an avatar that was registered.

FieldTypeDescriptionExample
idstringIdentifier of the avatar to remove'com.myplugin.myavatar'

Example

this.user.unregisterAvatar('com.myplugin.myavatar')

getAvatarData() : Promise<AvatarProps | null>

Returns the user's avatar data, or null if the user does not have a custom avatar selected.

See user.registerAvatar(props) for details of the fields returned. It also includes the extra fields pluginID and pluginName which represents the plugin which was used to register the avatar.

Example

const avatarData = await this.user.getAvatarData()
console.log(avatarData) // => { id: 'com.myplugin.myavatar', name: 'My Avatar', type: 'humanoid', imageURL: 'https://example.com/preview.jpg', properties: { url: '...' }, height: 1.8, walkingSpeed: 2, runningSpeed: 4, hookOnSetup: 'myplugin.onSetup', pluginID: 'com.myplugin', pluginName: 'My Plugin' }

setAvatarData(props: AvatarProps) : Promise<void>

Switches the user to the specified avatar data, which may prompt the user to confirm if they want to switch avatars.

See user.registerAvatar(props) for details of the fields that can be specified.

Example

await this.user.setAvatarData({
  id: 'com.myplugin.myavatar',
  name: 'My Avatar',
  type: 'humanoid',
  imageURL: 'https://example.com/preview.jpg', // or this.paths.absolute('./preview.jpg')
  properties: { url: '...' },
  height: 1.8,
  walkingSpeed: 2,
  runningSpeed: 4,
  hookOnSetup: 'myplugin.onSetup'
})

overrideAvatarAnimation(props: AnimationProps | null) : Promise<boolean>

Performs a custom animation override on the current avatar. All users will see the animation. This can be used to play once-off animations or to perform looping animations that are stopped only when the user tries to move around. You can also pass in null to this function to cancel any existing animation overrides.

Returns true if the animation was played until the end, or false if it was cancelled.

Note that all animation names must exclude the type prefix. For example, if you want to play a sit animation on the humanoid skeleton, just specify sit and the app will look for and play a humanoid.sit animation if the user's avatar is a humanoid type.

Also see objects.registerAnimations(url) for loading custom animations, or custom avatars for creating your own avatar and attaching custom animations to it.

FieldTypeExampleDescription
animation_startstring'sit_start'An optional animation to play once at the start of the override.
animationstring'sit_loop'The animation to play during the override.
animation_endstring'sit_end'An optional animation to play once at the end of the override.
loopnumber1Can be either a number representing the number of times to loop the animation, or true to loop continuously. Default = 1.
fixed_movementobject{ x: 0, y: 0, z: 0 }If specified, this prevents the user from moving, instead moving at a fixed rate of meters per second in the specified direction. Specify 0 for x, y and z to prevent the user from moving at all.
cancel_modestring'smooth'Specifies how the animation acts when cancelled by user movement. Specify 'smooth' (the default) to interrupt the loop but continue to play until the end, specify 'immediate' to immediately cancel the animation, or specify 'none' to never cancel.

Warning: If you specify 'none' you must cancel the animation yourself by passing in null to this function, or else the user will never be able to move again.
mergebooleantrueIf true, the animation will not replace the avatar's animation, it will instead be blended together with the default idle, walk, run etc animations. This can be used to play animations that only affect certain parts of the avatar's body, for example waving an arm while still letting the user walk around at the same time, etc. Default = false.

Example

const success = await this.user.overrideAvatarAnimation({
  animation_start: 'sit_start',
  animation: 'sit_loop',
  animation_end: 'sit_end',
  loop: true,
  fixed_movement: { x: 0, y: 0, z: 0 },
  cancel_mode: 'smooth',
  merge: true
})
console.log(success) // => true

showShutdownScreen(msg: string, title: string, btnText: string) : void

Shows an orange overlay indicating that the app has been shutdown.

FieldTypeDescriptionExample
msgstringMessage to show"You have been removed from this space."
titlestringTitle of the screen"Kicked Out"
btnTextstringText to show on the button"Reload"

Example

this.user.showShutdownScreen("You have been removed from this space.", "Kicked Out", "Reload")

showAvatarSelectPopup() : void

Shows the screen that allows a user to select their avatar.

Example

this.user.showAvatarSelectPopup()

sendAnalytics(key, value) : void

Send custom analytics data to the backend. Enterprise customers may use this to submit data for custom reports that they request from their Vatom representative.

ParameterTypeDescriptionExample
keystringsingle word name for data to be collected"IdOfUserEnteringThirdRoom"
valuestring, number, or objectdata to be collected"userEvan123"

Example

this.user.sendAnalytics("IdOfUserEnteringThirdRoom", "userEvan123")