Skip to main content

UnityVecEnv

UnityVecEnv connects Unity environments to Python reinforcement-learning code through a Gymnasium-compatible vector environment API.

Development status: Alpha. UnityVecEnv is under active development. APIs, the communication protocol, and package structure may change between minor releases. Pin exact versions, use matching Python and Unity package versions, and evaluate it carefully before using it in production-critical workloads.

Features

  • A standard Gymnasium VectorEnv interface for Unity environments.
  • Many agents batched inside one Unity process.
  • Multiple Unity processes exposed as one environment with FlattenedVectorEnvThreaded.
  • Continuous, discrete, and mixed action/observation spaces, plus visual observations.
  • Gymnasium NEXT_STEP and SAME_STEP autoreset modes.
  • Typed per-agent info values and run-level environment parameters.
  • Optional ONNX export and Unity tensor-renaming utilities.

How it works

Python training loop
        |
        | Gymnasium VectorEnv API
        v
unity-vecenv Python client
        |
        | localhost HTTP + Protocol Buffers
        v
Unity Editor or built player
        |
        v
GymVecEnvManager + GymAgent instances

Unity runs the simulation and an embedded local HTTP server. Python sends batched actions and receives observations, rewards, termination flags, and custom info values.

Requirements

Component Supported version
Python 3.10 or newer
Unity Editor Unity 6 (6000.0) baseline
Gymnasium 1.2 or newer, below 2.0
Unity Inference Engine 2.4.1, installed automatically by the Unity package

During the Alpha phase, use the same release number for both packages. For example, Python package 0.1.9 should be paired with Unity tag v0.1.9.

Installation

Python client

pip install unity-vecenv

This installs only the Python client. It does not install the Unity Editor, the Unity package, or a built Unity environment.

Install the optional ONNX export and model-renaming utilities with:

pip install "unity-vecenv[onnx]"

For CUDA-enabled inference or export, install the appropriate PyTorch build for your system before installing the ONNX extra.

Unity package

In Unity, select Window > Package Manager > + > Install package from git URL, or add the package to your project's Packages/manifest.json:

{
  "dependencies": {
    "com.mka.gymvecenv": "https://github.com/martkartasev/UnityVecEnv.git?path=/Unity#vX.Y.Z"
  }
}

Replace X.Y.Z with the version installed in Python. Tagged releases are listed on the GitHub Releases page.

Your Unity scene needs a GymAgent subclass. The GymVecEnvManager is created automatically at runtime. See the Unity setup guide for agent implementation and scene configuration.

Usage

Launch a built Unity environment

from unity_vecenv import UnityVectorEnv

env = UnityVectorEnv(
    executable_path="path/to/MyGame.exe",
    num_envs=16,
    no_graphics=True,
    time_scale=10,
)

try:
    observations, info = env.reset()

    for _ in range(1_000):
        actions = env.action_space.sample()
        observations, rewards, terminated, truncated, info = env.step(actions)
finally:
    env.close()

Connect to the Unity Editor

Start the configured scene in Play Mode, then connect to its listening port without starting another Unity process:

from unity_vecenv import UnityVectorEnv

env = UnityVectorEnv(
    start_process=False,
    port=50010,
    num_envs=4,
)

Documentation and support

License

UnityVecEnv is available under the MIT License.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unity_vecenv-0.1.9.tar.gz (29.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unity_vecenv-0.1.9-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

Details for the file unity_vecenv-0.1.9.tar.gz.

File metadata

  • Download URL: unity_vecenv-0.1.9.tar.gz
  • Upload date:
  • Size: 29.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for unity_vecenv-0.1.9.tar.gz
Algorithm Hash digest
SHA256 989650d894da35ba527a3b96080a736d3999bfb35a5027c1000aba3aec82fe09
MD5 b2d3ef219d4d446dbbbf94633b5c6440
BLAKE2b-256 eba1db4ca5393534a2660a7fd35fafb586af47cd26c7881634b61a173841eb6a

See more details on using hashes here.

Provenance

The following attestation bundles were made for unity_vecenv-0.1.9.tar.gz:

Publisher: publish-pypi.yml on martkartasev/UnityVecEnv

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file unity_vecenv-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: unity_vecenv-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 32.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for unity_vecenv-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 368e97a1a4ad9e6e6fb07008c528251240609949e0031c1ab7c7224c2733f532
MD5 b9cd268f6e1e5a0f2d7c261661e556f4
BLAKE2b-256 37e43c93a1657a11baaf48bb77070a6fd7fc433f059add9f2da3c64f37d831a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for unity_vecenv-0.1.9-py3-none-any.whl:

Publisher: publish-pypi.yml on martkartasev/UnityVecEnv

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page