I created a game in Unity and I’m trying to train an agent in this game with ml-agents tool. I implemented algorithms in Python to train agent and for interacting with unity environment I’m using API from official documentation (env = UnityEnvironment(file_name=None, seed=1, side_channels=[ ])
). Now I want to turn off rendering to train agent as fast as possible. I found that --batchmode
option could be possible solution but when I tried it, Unity couldn’t connect to ml-agents Python API (without --batchmode
option it works, it connects to address and port and starts training).
Can you please help me why it doesn’t work with this option and how to solve this or is there another way how to do it?
Command to run Unity which I used:
"PathToUnityExecutable\Unity.exe" -batchmode -logfile -projectPath "pathToProject" -executeMethod RunGame.PlayGame
Code for “RunGame” class with “PlayGame” method is below.
public static class RunGame {
public static bool isBatchMode = false;
public static void PlayGame()
{
isBatchMode = true;
EditorSceneManager.OpenScene("Assets/Scenes/Main.unity");
EditorApplication.EnterPlaymode();
}
public static void ExitGame(int errorCode=0)
{
if (Application.isBatchMode)
EditorApplication.Exit(errorCode);
isBatchMode = false;
}
}
Thank you for your answers!