Search Unity

Resolved Fewer observations(0) made than vector size (reoccurs upon disabling agents)

Discussion in 'ML-Agents' started by ongr1996_unity, Sep 17, 2021.

  1. ongr1996_unity

    ongr1996_unity

    Joined:
    Nov 13, 2020
    Posts:
    6
    For context, I am making a multi-agent collision avoidance environment and I created a Vector Observation Space size of 2
    1) The relative angle of the agent to it's desired goal (0 when on direct path, ranges between -180 to 180 degrees)
    2) Distance between Agent and Goal
    Upon agent collision with a wall or another agent (Ray Perception 3D) they deactivate so naturally there becomes fewer observations made than the determined vector size.
    Is it possible to disable the Vector Observation Space of agents right before they are disabled the environment?
    In the case it is possible, are either of these two ideas on the right track?

    1) If statement within the CollectObservations function to only AddObservation when Agent.gameObject.SetActive(True) :

    if (gameObject.activeInHierarchy == true)
    {
    sensor.AddObservation(relAngle);
    sensor.AddObservation(relDistance);
    }


    2) Initialize a boolean (isGone) to False. OnEpisodeBegin still equal false. And, since the Agent script calls functions from my environment script when it collides with something (which Turns off the agent), I make the boolean true. Like this:

    void OnCollisionEnter(Collision col)
    {
    if (col.transform.CompareTag("agent"))
    {
    isGone = true;
    m_EnvController.CrashedIntoAgent(this);
    }
    }
     
    Last edited: Sep 20, 2021
  2. ongr1996_unity

    ongr1996_unity

    Joined:
    Nov 13, 2020
    Posts:
    6
    I figured out the error had nothing to do with any parts of the script. It turned out that there was an extra ml-agents agent(script) inside the inspector of all my agents alongside my custom script (despite my prefab not having the script). Not sure when that got there, but it was the issue. Hope it helps if anyone has any errors with the Vector Observation Space while deactivating agents.