Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Changing VectorAction SpaceSize on BehaviorParameters component seems to have no effect.

Discussion in 'ML-Agents' started by Imakhiil, Apr 4, 2020.

  1. Imakhiil

    Imakhiil

    Joined:
    Oct 11, 2013
    Posts:
    96
    I tried modifying it but no matter what the value in the inspector is, the array passed to the OnActionReceived method on the Agent is always 2. I'm not sure if it's a bug or me misunderstanding something. It's the only Agent in the scene.
     
  2. Imakhiil

    Imakhiil

    Joined:
    Oct 11, 2013
    Posts:
    96
    So, after some debugging here is what the issue was and how to reproduce it.

    Consider an Agent with BehaviorType set to Default or Heuristic Only on its BehaviorParameters. Let's say it's space size is 3. If your heuristic doesn't set all three values of the array and instead, say, 2 first elements, the array will be resized under the hood somewhere on the way between Heuristic and OnActionReceived.

    A heuristic like this:
    Code (CSharp):
    1.     public override float[] Heuristic()
    2.     {
    3.         var action = new float[3];
    4.         action[0] = Input.GetAxis("Horizontal");
    5.         action[1] = Input.GetAxis("Vertical");
    6.         return action;
    7.     }
    will produce crashes even tho it's size of the array is clearly correct. It gets resized to an array with Length 2. To prevent these errors one needs to actually set all elements, like so:
    Code (CSharp):
    1.     public override float[] Heuristic()
    2.     {
    3.         var action = new float[3];
    4.         action[0] = Input.GetAxis("Horizontal");
    5.         action[1] = Input.GetAxis("Vertical");
    6.         action[2] = 0.0f;
    7.         return action;
    8.     }
    I think it's very counterintuitive. I wasn't able to find what exactly in the library resized it but I think it counts as a bug. Or is it the intended behavior? If it is, I really think it should be documented clearly.
     
  3. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,768
  4. andrewcoh_unity

    andrewcoh_unity

    Unity Technologies

    Joined:
    Sep 5, 2019
    Posts:
    162
    What is the crash message?