Skip to content

Latest commit

 

History

History
444 lines (193 loc) · 7.29 KB

File metadata and controls

444 lines (193 loc) · 7.29 KB

Home > client > HytopiaUI

HytopiaUI class

Global API for interacting with the HYTOPIA game client. Access via the hytopia global variable in your client-side HTML UI code.

Signature:

export declare class HytopiaUI 

Properties

Property

Modifiers

Type

Description

cameraFar

readonly

number

Maximum render distance of the camera in world units. Objects beyond this distance are not rendered.

cameraNear

readonly

number

Minimum render distance of the camera in world units. Objects closer than this distance are not rendered.

gltfLoader

readonly

typeof GLTFLoader

Access to a THREE.js GLTFLoader instance for loading 3D models, useful if you want to render models in your UI.

isMobile

readonly

boolean

Detects if the player is on a mobile device. Use this to adjust UI layout or controls, etc.

three

readonly

typeof THREE

Access to the THREE.js library for advanced 3D rendering. Use for custom visual effects in your UI.

Methods

Method

Modifiers

Description

connectArrow(source, target, options)

Creates an arrow between two points or entities.

disconnectArrow(arrowId)

Removes an arrow by its ID.

filterProfanity(text)

Filters inappropriate language from text by replacing profanity with asterisks. Use this to sanitize user-generated content displayed in your UI (e.g., chat messages, usernames).

freezePointerLock(freeze)

Freezes or unfreezes the pointer lock state. Preventing player inputs from automatically locking or unlocking the pointer. Esc key will still unlock the pointer - this is a system level feature that cannot be overriden. Pointer lock only affects Desktop devices.

getEntityIdByName(name)

Finds an entity by its name property and returns its ID. If multiple entities have the same name, returns the first one found.

getPlayerEntityId()

Gets the entity ID of the current player's entity. Returns undefined if the player entity is not yet initialized.

getSceneUITemplateRenderer(templateId)

Retrieves a registered Scene UI template renderer function.

hasProfanity(text)

Checks if text contains inappropriate language. Useful for validating input before sending to the server.

hasSceneUITemplateRenderer(templateId)

Checks whether a Scene UI template is currently registered.

lockPointer(lock, maintainInput)

Controls pointer lock for your UI. When locked, the cursor is hidden and mouse movement controls the camera. Call with true when hiding your UI so players can control the camera, false when showing UI that needs cursor interaction. Pointer lock only affects Desktop devices.

offAllData()

Removes all registered data event listeners.

offData(callback)

Removes a specific data event listener. Pass the same callback function used in onData().

onData(callback)

Registers a listener for data received by the server from player.ui.sendData().

pressInput(input, pressed)

Simulates player input programmatically. Useful for creating custom UI controls that trigger game actions, such as for mobile UI buttons.

registerSceneUITemplate(templateId, templateRenderer)

Registers a custom Scene UI template that will instantiate when a SceneUI on the server for the given templateId is loaded. Templates define how your UI should render for each Scene UI instance created by the server.

sendData(data)

Sends data from your UI to the game server. The server receives this via player.ui.on(PlayerUIEvent.DATA, callback). Use this to notify the server of player actions taken in your custom UI.

setEntityColorCorrection(entityId, color)

Applies color tint to an entity on the client only (does not affect other players' view). Use for client-side visual effects like highlighting, damage indicators, or team colors.

setMouseSensitivityMultiplier(multiplier)

Adjusts the user's base mouse sensitivity for camera rotation. Values above 1.0 increase sensitivity, below 1.0 decrease it. Useful for providing sensitivity settings in your UI options menu.

unregisterLoadedSceneUITemplates()

Removes all custom Scene UI templates. Built-in HYTOPIA templates (prefixed with hytopia:) are preserved. Use this when cleaning up your game code on disconnect or world change.

unregisterSceneUITemplate(templateId)

Removes a registered Scene UI template. The template will no longer be available for new Scene UI instances. Existing instances using this template are not affected.