Skip to main content

How do I pass parameters/config to my server when creating a room?

Many games need to pass parameters or configurations to the process upon startup (e.g. game mode, map, etc).

Hathora helps users solve this with our flexible roomConfig, which allows users to pass in any arbitrary string (like a JSON string), when you call CreateRoom() or CreateLobby().

How to use roomConfig

The way you access roomConfig depends on whether your game server is designed to handle more than 1 match per process or not.

Single match per process

For the case when your game server is built to handle 1 match per process, you can grab the roomConfig using the default environment variable HATHORA_INITIAL_ROOM_CONFIG.

Multiple matches per process

When your game server can host multiple matches per process, you will need logic to handle getting the roomConfig from each roomId. In this case, you should:

  1. Store your HATHORA_DEV_TOKEN as an environment variable via deployment configuration (for use in API calls)
  2. Use the default environment variable HATHORA_PROCESS_ID to call GetActiveRoomsForProcess() from your game server code or init script (via Dockerfile). This will return roomConfigs for all active roomIds. Alternatively, if you already have a roomId you can call GetRoomInfo().