<aside> 💡 Gym_unrealcv is a Python library that provides an interface for using Unreal Engine (UE4/UE5) with OpenAI's Gym. It allows you to create reinforcement learning environments using Unreal Engine and UnrealCV.

</aside>

1. Installation:

You can install gym_unrealcv using pip in the source folder:

pip install -e .

2. Creating an Environment:

To create an environment, you can use the gym.make() function with the ID of the environment you want to create. For example:

import gym 
import gym_unrealcv
env = gym.make('UnrealTrack-SuburbNeighborhood_Day-ContinuousMask-v0') # build an environment
# Environment Name: *Unreal{Task}-{Scene_Name}-{Action Space}{Observation Space}-{version}*

3. Interacting with the Environment:

You can interact with the environment using the step() and reset() methods. The step() method takes an action and returns an observation, a reward, a done flag (indicating if the episode is over), and info (extra information which can be useful for debugging). The reset() method resets the environment to its initial state and returns the initial observation.

obs = env.reset() # reset the environment and get the initial observation

action = env.action_space.sample() # Sample a random action

# take the action and get the reward and new observation from the environment
obs, reward, done, info = env.step(action) 

4. Rendering the Environment:

If you want to visualize the environment, you can use the render() method, or use cv2.imshow() method to visualize the observation data.

*img = env.render(mode='rgb_array')*
*img = img[..., ::-1]  # bgr->rgb*
cv2.imshow('show', img)

obs, rewards, done, info = env.step(actions)
cv2.imshow('show', obs[0])
cv2.waitKey(1)

5. Closing the Environment:

Once you're done with the environment, you can close it using the close() method:

env.close()

6. Toolkits

We also provide several wrappers that you can use to modify the environment in various ways, including configuring the UE binaries while launching, control the simulated time, set early done condition, randomize the populations.

Toolkits for Gym Envs