I installed MLagents on macox and I can run mlagents-learn without errors. I added the following script to the agent and in the Behavior Parameters I set Heuristic Only. However, the Heuristic function is not invoked. Someone can help me?
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;
using UnityEngine;
public class MoveToGoalAgent : Agent
{
[SerializeField] private Transform targetTransform;
[SerializeField] private float speed = 3f;
public override void CollectObservations(VectorSensor sensor)
{
Debug.Log("CollectObservations");
sensor.AddObservation(transform.position);
sensor.AddObservation(targetTransform);
}
public override void OnActionReceived(ActionBuffers actions)
{
Debug.Log("OnActionReceived");
float moveX = actions.ContinuousActions[0];
float moveZ = actions.ContinuousActions[1];
transform.position += new Vector3(moveX, 0, moveZ) * Time.deltaTime * speed;
}
public void OnTriggerEnter(Collider other)
{
Debug.Log("OnTriggerEnter");
if (other.TryGetComponent<Goal>(out Goal goal))
{
SetReward(1f);
EndEpisode();
}
if (other.TryGetComponent<Wall>(out Wall wall))
{
SetReward(-1f);
EndEpisode();
}
}
public override void Heuristic(in ActionBuffers actionsOut)
{
Debug.Log("Heuristic");
var continuousActionsOut = actionsOut.ContinuousActions;
continuousActionsOut[0] = Input.GetAxisRaw("Horizontal") ;
continuousActionsOut[1] = Input.GetAxisRaw("Vertical");
}
public override void OnEpisodeBegin()
{
Debug.Log("OnEpisodeBegin");
transform.position = Vector3.zero;
}
}