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
VectorEnvinterface 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_STEPandSAME_STEPautoreset 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
989650d894da35ba527a3b96080a736d3999bfb35a5027c1000aba3aec82fe09
|
|
| MD5 |
b2d3ef219d4d446dbbbf94633b5c6440
|
|
| BLAKE2b-256 |
eba1db4ca5393534a2660a7fd35fafb586af47cd26c7881634b61a173841eb6a
|
Provenance
The following attestation bundles were made for unity_vecenv-0.1.9.tar.gz:
Publisher:
publish-pypi.yml on martkartasev/UnityVecEnv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unity_vecenv-0.1.9.tar.gz -
Subject digest:
989650d894da35ba527a3b96080a736d3999bfb35a5027c1000aba3aec82fe09 - Sigstore transparency entry: 2232104205
- Sigstore integration time:
-
Permalink:
martkartasev/UnityVecEnv@30b1e55a7f7405df3f79285d3eb159c7548c58bb -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/martkartasev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@30b1e55a7f7405df3f79285d3eb159c7548c58bb -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
368e97a1a4ad9e6e6fb07008c528251240609949e0031c1ab7c7224c2733f532
|
|
| MD5 |
b9cd268f6e1e5a0f2d7c261661e556f4
|
|
| BLAKE2b-256 |
37e43c93a1657a11baaf48bb77070a6fd7fc433f059add9f2da3c64f37d831a6
|
Provenance
The following attestation bundles were made for unity_vecenv-0.1.9-py3-none-any.whl:
Publisher:
publish-pypi.yml on martkartasev/UnityVecEnv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unity_vecenv-0.1.9-py3-none-any.whl -
Subject digest:
368e97a1a4ad9e6e6fb07008c528251240609949e0031c1ab7c7224c2733f532 - Sigstore transparency entry: 2232104767
- Sigstore integration time:
-
Permalink:
martkartasev/UnityVecEnv@30b1e55a7f7405df3f79285d3eb159c7548c58bb -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/martkartasev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@30b1e55a7f7405df3f79285d3eb159c7548c58bb -
Trigger Event:
push
-
Statement type: