Search Unity

How to access behavior type of an Agent object in code?

Discussion in 'ML-Agents' started by ailuropoda0, Oct 27, 2020.

  1. ailuropoda0

    ailuropoda0

    Joined:
    Feb 26, 2020
    Posts:
    9
    In my implementation, OnActionReceived() is slightly different in a training mode and heuristic mode(or user playing mode).

    So I would like to get whether this (Unity.MLAgents.)Agent object has 'Heuristic' behavior type or 'Default' behavior type.

    I can't find any methods or member variables related with it. Is there any way to get what behavior type the Agent has in the code?
     
  2. mbaske

    mbaske

    Joined:
    Dec 31, 2017
    Posts:
    473
    In your agent class, you can use
    GetComponent<Unity.MLAgents.Policies.BehaviorParameters>().BehaviorType;
    to retrieve the BehaviorType set in the inspector. This might not match the actual policy though, depending on wether a model was provided or not.
    The policy is generated here:
    https://github.com/Unity-Technologi...s/Runtime/Policies/BehaviorParameters.cs#L199

    Or you could just set a bool flag in your Heuristic method, since it is only called when the agent is in heuristic mode (prior to OnActionReceived).
     
  3. ailuropoda0

    ailuropoda0

    Joined:
    Feb 26, 2020
    Posts:
    9
    Thanks, it works.