Environment Variables & Metadata
GameFlow automatically injects a set of environment variables and metadata into every game server at runtime. These are available without any additional configuration from the developer.
Environment Variables
These values are injected as standard environment variables into the game server container. They are available via process.env (JS/TS),Environment.GetEnvironmentVariable (C#/Unity), or equivalent in your runtime or engine.
| Variable | Type | Description | Example |
|---|---|---|---|
GAMEFLOW_REGION | string | The region where the game server is running. | us-east |
GAMEFLOW_DEFAULT_PORT | string | The primary/default port assigned to the game server container. | 7777 |
GAMEFLOW_{NAME}_PORT | string | One env var per additional port configured on the fleet, where {NAME} is the port label uppercased with spaces replaced by underscores. | 9090 |
Usage Examples
C# / Unity:
var region = Environment.GetEnvironmentVariable("GAMEFLOW_REGION");
var defaultPort = Environment.GetEnvironmentVariable("GAMEFLOW_DEFAULT_PORT");
// Server running in us-east on port 7777
Debug.Log($"Server running in {region} on port {defaultPort}");
var voiceChatPort = Environment.GetEnvironmentVariable("GAMEFLOW_VOICE_CHAT_PORT");
// Voice chat on port 9090
Debug.Log($"Voice chat on port {voiceChatPort}");
JS/TS:
const defaultPort = process.env.GAMEFLOW_DEFAULT_PORT;
const region = process.env.GAMEFLOW_REGION;
// Server running in us-east on port 7777
console.log(`Server running in ${region} on port ${defaultPort}`);
const voiceChatPort = process.env.GAMEFLOW_VOICE_CHAT_PORT;
// Voice chat on port 9090
console.log(`Voice chat on port ${voiceChatPort}`);
Additional Ports
When you configure additional ports on your fleet, GameFlow generates an environment variable for each one using the naming convention GAMEFLOW_{NAME}_PORT, where {NAME} is the port label uppercased with spaces replaced by underscores.
For example, a fleet configured with a default port and two additional ports labeled "voice chat" and "debug" would receive:
| Environment Variable | Value |
|---|---|
GAMEFLOW_DEFAULT_PORT | 7777 |
GAMEFLOW_VOICE_CHAT_PORT | 9090 |
GAMEFLOW_DEBUG_PORT | 9091 |
Metadata
Per-session metadata such as the launch payload is delivered to your server and read using the GameFlow Game Server SDK.
| Annotation | Type | Description | Example |
|---|---|---|---|
GAMEFLOW_PAYLOAD | string (JSON) | Optional JSON string with player or session data, passed at server creation or allocation time. | {"players": ["p1", "p2"]} |
Reading the Payload
Retrieve the launch payload with the SDK's payload() call. It returns an opaque string (whatever you passed at allocation), so parse it however you produced it. To react when a server is reassigned to a new match, subscribe with onPayloadChange; see the SDK Quickstart.
C# / Unity:
var payload = await gf.Payload(); // string (null when none)
if (!string.IsNullOrEmpty(payload)) {
var data = JsonConvert.DeserializeObject(payload);
Debug.Log(data); // {"players": ["p1", "p2"]}
}
JS/TS
const payload = await gf.payload(); // string | undefined
if (payload) {
const data = JSON.parse(payload);
console.log(data); // {"players": ["p1", "p2"]}
}
Godot / GDScript:
var res := await gf.payload()
if res.value != null:
var data = JSON.parse_string(res.value)
print(data) # {"players": ["p1", "p2"]}
How Are These Different from Custom Environment Variables?
When creating a game in GameFlow, you can define custom environment variables that are baked into the container spec. These are static values used for configuration that doesn't change between sessions (e.g., LOG_LEVEL).
GameFlow-provided values are different:
- Automatically injected by the platform, no manual configuration needed.
GAMEFLOW_REGION,GAMEFLOW_DEFAULT_PORT, andGAMEFLOW_{NAME}_PORTare environment variables that reflect the runtime context of each server instance.GAMEFLOW_PAYLOADis not an environment variable; it carries dynamic, per-session data passed at allocation or server creation time, and is read with the GameFlow Game Server SDK'spayload()call.
This separation allows developers to keep static configuration in the image while still receiving dynamic, per-instance and per-session data at runtime.