hytopia
Version:
The HYTOPIA SDK makes it easy for developers to create massively multiplayer games using JavaScript or TypeScript.
198 lines (93 loc) • 3.05 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [server](./server.md) > [WorldManager](./server.worldmanager.md)
## WorldManager class
Manages all worlds in a game server.
When to use: creating additional worlds, routing players, or querying the active world set. Do NOT use for: instantiating `World` directly for gameplay; use `WorldManager.createWorld` to ensure IDs and lifecycle are managed consistently.
**Signature:**
```typescript
export default class WorldManager
```
## Remarks
Access via `WorldManager.instance` — do not construct directly.
<h2>Events</h2>
This class emits global events with payloads listed under `WorldManagerEventPayloads`<!-- -->.
## Example
```typescript
import { WorldManager } from 'hytopia';
const worldManager = WorldManager.instance;
const newWorld = worldManager.createWorld({
name: 'My New World',
skyboxUri: 'skyboxes/partly-cloudy',
});
```
\*\*Category:\*\* Core
## Properties
<table><thead><tr><th>
Property
</th><th>
Modifiers
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td>
[instance](./server.worldmanager.instance.md)
</td><td>
`static`
`readonly`
</td><td>
[WorldManager](./server.worldmanager.md)
</td><td>
The global WorldManager instance (singleton).
\*\*Category:\*\* Core
</td></tr>
</tbody></table>
## Methods
<table><thead><tr><th>
Method
</th><th>
Modifiers
</th><th>
Description
</th></tr></thead>
<tbody><tr><td>
[createWorld(options)](./server.worldmanager.createworld.md)
</td><td>
</td><td>
Creates and starts a new world with a unique ID.
Use for: additional game rooms, arenas, or isolated simulations. Do NOT use for: deferred world creation without starting; this always starts.
</td></tr>
<tr><td>
[getAllWorlds()](./server.worldmanager.getallworlds.md)
</td><td>
</td><td>
Gets all worlds currently managed by the server.
</td></tr>
<tr><td>
[getDefaultWorld()](./server.worldmanager.getdefaultworld.md)
</td><td>
</td><td>
Gets the default world, creating it if it does not exist.
Use for: a single-world game or as a safe fallback when routing players. Do NOT use for: creating specialized worlds with unique options.
</td></tr>
<tr><td>
[getWorld(id)](./server.worldmanager.getworld.md)
</td><td>
</td><td>
Gets a world by its ID.
</td></tr>
<tr><td>
[getWorldsByTag(tag)](./server.worldmanager.getworldsbytag.md)
</td><td>
</td><td>
Gets all worlds with a specific tag.
</td></tr>
<tr><td>
[setDefaultWorld(world)](./server.worldmanager.setdefaultworld.md)
</td><td>
</td><td>
Sets the default world players join on connect.
Use for: changing the lobby or main world at runtime. Do NOT use for: moving already connected players; use `Player.joinWorld`<!-- -->.
</td></tr>
</tbody></table>