Change the Behavior between Heuristic and Inference in code?

I would like to change the behaviour during runtime to be able to choose if my agent is controlled by the trained model or by manual input.

It works during runtime when running the application in the editor by changing the Behavior Type in the inspector but how can I do the same with code in my control script?

In your agent code:

private void Start()
{
    if (ManualControl)
    {
        BehaviorParameters  AIBehavior = GetComponent<BehaviorParameters>();
        AIBehavior.BehaviorType = Unity.MLAgents.Policies.BehaviorType.HeuristicOnly;
    }

}
1 Like