docs.unity.cn
Search Results for

    Show / Hide Table of Contents

    Field MaxStep

    The maximum number of steps the agent takes before being done.

    Namespace: Unity.MLAgents
    Assembly: solution.dll
    Syntax
    [FormerlySerializedAs("maxStep")]
    [HideInInspector]
    public int MaxStep
    Returns
    Type Description
    int

    The maximum steps for an agent to take before it resets; or 0 for unlimited steps.

    Remarks

    The max step value determines the maximum length of an agent's episodes. Set to a positive integer to limit the episode length to that many steps. Set to 0 for unlimited episode length.

    When an episode ends and a new one begins, the Agent object's OnEpisodeBegin() function is called. You can implement OnEpisodeBegin() to reset the agent or remove it from the environment. An agent's episode can also end if you call its EndEpisode() method or an external process resets the environment through the Academy.

    Consider limiting the number of steps in an episode to avoid wasting time during training. If you set the max step value to a reasonable estimate of the time it should take to complete a task, then agents that haven’t succeeded in that time frame will reset and start a new training episode rather than continue to fail.

    Examples

    To use a step limit when training while allowing agents to run without resetting outside of training, you can set the max step to 0 in Initialize() if the Academy is not connected to an external process.

    using Unity.MLAgents;
    
    public class MyAgent : Agent
    {
        public override void Initialize()
        {
            if (!Academy.Instance.IsCommunicatorOn)
            {
                this.MaxStep = 0;
            }
        }
    }

    Note: in general, you should limit the differences between the code you execute during training and the code you run during inference.

    In This Article
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023