Search Unity

Question Unity freezing when training AI Agent

Discussion in 'ML-Agents' started by PaeddyZ, Dec 6, 2022.

  1. PaeddyZ

    PaeddyZ

    Joined:
    Jan 28, 2020
    Posts:
    1
    Hello

    I've just recently started using ML Agents.
    I noticed that Unity freezes for about 2 seconds every 5 seconds when training the AI agents.

    Is this normal? Can this be optimized?

    Thanks!
     
  2. GamerLordMat

    GamerLordMat

    Joined:
    Oct 10, 2019
    Posts:
    185
    it's normal. You can build your game with "serveroption on" and then over the console give it as a paramter (I think with --env=). That is faster
     
  3. hughperkins

    hughperkins

    Joined:
    Dec 3, 2022
    Posts:
    191
    Where do we set this option? I dont see it in player options, when building?
     
  4. GamerLordMat

    GamerLordMat

    Joined:
    Oct 10, 2019
    Posts:
    185
    hello,
    yes,when building you can check serverbuild which deactivates all rendering stuff (watch out for use with rendertextures/ visual sensor component, it deactivates it too as far as I know). Then when starting Mlagents over the console you write mlagents-learn env=YourPathToTheBuildDirectory --no-graphics

    when using pyhsics, set: time-scale=1 ; gives better results but is slower (the timescale=1 is not actually realtime but 1 physics frame for a FixedStep). Also use cuda if possible, it made my CNN run 10x faster (as expected).
     
    Last edited: Dec 27, 2022
    maxkcy and NeneChico like this.