Help - Version 0.24 - OnActionReceived not firing

Windows 8.1 x64
Card: GTX960
Python 3.79

[from command line with unity logo]
Version information:
ml-agents: 0.24.0,
ml-agents-envs: 0.24.0,
Communicator API: 1.4.0,
PyTorch: 1.7.1+cu110

Below
OnActionReceived not firing

I tried this will build 12 and got a basic setup to work, though I would like to get this newer version with ActionBuffers working.

Just using Debug.Log for now.

using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;
using UnityEngine;

public class AI_NPC_Warrior : Agent
{

    public override void OnEpisodeBegin()
    {
        Debug.Log("OnEpisodeBegin");
    }


    public override void CollectObservations(VectorSensor sensor)
    {
        sensor.AddObservation(transform.position);
       
        for (int i = 1; i <= 5; i++)
        {
            sensor.AddObservation(0);
            Debug.Log("CollectObservations : " + i);
        }
    }
   

    public override void OnActionReceived(ActionBuffers actionBuffers)
    {
        Debug.Log("OnActionReceived");
        Debug.Log(actionBuffers.DiscreteActions[0]);
    }
}

Any ideas would be great.

Do you have a decision requester component or ever call RequestDecision anywhere?

2 Likes

Hi Christopher and thank you for the reply.

I did not know about this, helped a bunch getting me on the right track.
I can get the OnActionReceived firing now.
Still have more to learn about Max size, Space size and Stacked vectors.

I’ll post my code once I get something that may help others.

by max size do you mean max step? If so, maxStep is the maximum number of steps the agent would take before it being done, resetting, and starting over.

Space size in the BehaviorParameters Component tells ML-Agents how many observations you want to make. From the code you posted above, you would want to set that to 8:

transform.Position is a Vector3 which is 3 floats. (size of 3)
Your loop adds 5 zeros as observations (size of 5)
Total number of observations is 3 + 5 = 8.

Stacked vectors give the Neural network a look back at previous observations. So let’s say you set Stack Vectors to 5, this means the neural network would get your observations from the current frame plus the previous 4 observations.

Let me know if that helps clarify anything. Also, all of these things are explained in the documentation if you’d like to read through it.