Unity Environments
Use logical partitions to organize your service data for testing, staging, and production workflows.
Read time 4 minutesLast updated 17 hours ago
Environments are logical partitions for Unity Gaming Services that contain data associated with your project. Examples can include game code using Cloud Code, or game configurations using Remote Config.
- Environments are isolated. This means that if you change data in one environment, data in other environments is not affected.
- You apply Environments at the project level.
- You can think of Environments as namespaces or labels for your data.
- Creating an environment doesn't provision resources; it enables you to tie data to a specific workspace.
Supported Services
The following services currently support Environments:- Analytics
- Cloud Code
- Cloud Content Delivery
- Cloud Save
- Economy
- Lobby
- Matchmaker
- Multiplayer Services
- Relay
- Remote Config
Managing environments
To access a project’s Environments from the Unity Dashboard:- Select Projects from the primary navigation menu.
- Select the project to which you want to apply Environments.
- Select the Environments tab.
Switching environments for a service
To switch the environment for a service in the Unity Dashboard:- Select Projects from the primary navigation menu.
- Select the project for which you want to change the environment.
- Select the Environments tab.
- Select the environment to use.
Accessing environments within Unity projects
Use the Services Core initialization options to initialize your Unity Gaming Services in the development environment you want the player to experience. If unspecified, Unity Gaming Services will initialize in the default “production” environment.
To do this, include the
Unity.Services.CoreUnity.Services.Core.EnvironmentsUnityServices.InitializeAsync()optionsIf no option is specified, the Environment Selector value is used. If no Environment Selector option is present, 'production' is used as the default. For more information, refer to Environment Selector.using Unity.Services.Authentication;using Unity.Services.Core;using Unity.Services.Core.Environments;using UnityEngine;class InitWithEnvironment : MonoBehaviour { async void Awake() { var options = new InitializationOptions(); options.SetEnvironmentName("dev"); await UnityServices.InitializeAsync(options); await AuthenticationService.Instance.SignInAnonymouslyAsync(); }}
Environments Recommended Practices
Configuration as Code
Most UGS services support implementing Configuration-as-Code practices. Configuration as Code is the practice of treating configurations the same as code. This approach enables versioning, code review, automated deployment, and eliminates manual environment setup across your development pipeline. It also lets you reuse configurations across projects and organizations.Recommended environment strategy
The recommended best practice is to use environments as follows:- Production environment: Live environment serving released applications, updated from stabilization branches.
- Staging environment: Production-like environment for final testing, updated from stabilization branches.
- Development environment: Shared integration environment for the team, updated from main development branch.
- Personal environments: Individual developer workspaces for experimentation and feature development. Only developers actively working on service-enabled features need personal environments to iterate safely and avoid impacting anyone's work.
Environment management tooling
Editor Deployment window
The Deployment Window is accessible through Services > Deployment in Unity Editor 2022 and later, once the package is installed. It allows you to deploy local service content to the services. It is the preferred way of iterating and working on service-enabled features. The following services are supported:- Cloud Code (JavaScript and C# modules)
- Economy
- Game Overrides (through the Services Tooling package)
- Remote Config
- Leaderboards
- Matchmaker
- Multiplay Hosting
- Access Control (through the Services Tooling package)
Unity Gaming Services CLI
Use the UGS CLI to call services' admin APIs, and todeployfetch- Access Control
- Cloud Code (Scripts and Modules)
- Remote Config
- Economy
- Leaderboards
- Matchmaker
- Triggers
- Schedules
Deploy and fetch workflow
You can use thedeployfetchDeploy command
Use thedeployWith source control:mkdir backup_prodmkdir staging_confugs fetch backup_prod --reconcile -s <specify the services here>ugs fetch staging_conf --reconcile -s <specify the services here>ugs deploy staging_conf -e production # promotion#rollbackugs deploy backup_prod -e production
Source control makes it easier to track what's being deployed, and automate deployments.git checkout origin/stableugs deploy ugs_config_folder#rollbackgit checkout tags/last-release -b stableugs deploy ugs_config_folder
Fetch command
Usefetchugs fetch ./staging-configs --environment-name staging --reconcile -s <services>ugs fetch ./prod-configs --environment-name production --reconcile -s <services>kdiff3 ./staging-configs ./prod-configs