Search Unity

Editor ML-Agents EnterPlayMode time?

Discussion in 'ML-Agents' started by Fr2, Feb 3, 2021.

  1. Fr2

    Fr2

    Joined:
    Jan 19, 2013
    Posts:
    39
    I've got a couple of pre-trained models which I created using separate Unity projects. I've imported them into my main game.

    When I click play in the Editor I'm noticing that the ML-Agent's Awake() script takes around 4.3 seconds during EnterPlayMode:

    upload_2021-2-3_16-28-52.png

    Final builds (iOS or standalone Windows) are almost instantaneous to launch, so I was curious to know what's happening in the background (Python API communication?).

    As I'm not actually doing any ML-Agent training in the main game, could this time be reduced?
     
  2. awjuliani

    awjuliani

    Unity Technologies

    Joined:
    Mar 1, 2017
    Posts:
    69
    Hi Fr2. I don't believe we do any significant ML-Agents specific initialization in the Awake function. Is there additional code you have in your Awake method which may be contributing to this 4.3 seconds?
     
  3. awjuliani

    awjuliani

    Unity Technologies

    Joined:
    Mar 1, 2017
    Posts:
    69
    Upon some further digging, it seems that this may be a known issue. Could you take a look at the issue here, and let me know if it seems to match your experience? It is specific to Windows, which is what I assume you are running the Editor in. https://github.com/Unity-Technologies/ml-agents/issues/4633.
     
  4. Fr2

    Fr2

    Joined:
    Jan 19, 2013
    Posts:
    39
    @awjuliani - thanks for investigating. I'm using Windows and can confirm the issue is the same as https://github.com/Unity-Technologies/ml-agents/issues/4633

    I've applied the suggested quick fix to RpcCommunicator.cs:

    Code (CSharp):
    1. #if UNITY_EDITOR
    2.             var result = m_Client.Exchange(WrapMessage(unityOutput, 200), deadline: DateTime.Now.AddSeconds(1));
    3. #else
    4.             var result = m_Client.Exchange(WrapMessage(unityOutput, 200));
    5. #endif
    and am no longer seeing a 4s delay:

    upload_2021-2-4_13-34-21.png

    I'll need to remember to revert RpcCommunicator.cs changes when re-training.