Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Float and Bool on action received

Discussion in 'ML-Agents' started by TheJarmanitor, Jun 21, 2020.

  1. TheJarmanitor

    TheJarmanitor

    Joined:
    Mar 18, 2018
    Posts:
    20
    Can I have different types of variables on ActionsReceived and ActionsOut? I need floats for movement and a Bool for attack but the examples I've seen only use float[ ]
     
  2. mbaske

    mbaske

    Joined:
    Dec 31, 2017
    Posts:
    473
    You can just use a float and do a comparison
    bool attack = actions[i] > 0;
     
  3. TheJarmanitor

    TheJarmanitor

    Joined:
    Mar 18, 2018
    Posts:
    20
    How would I do it on ActionsOut? I tried using an if sentence assigning it to a 1 or 1f, but it's telling me I'm out of index
     
  4. celion_unity

    celion_unity

    Joined:
    Jun 12, 2019
    Posts:
    289
    @TheJarmanitor What are the Vector Action > Space Type and Space Size for your agent? If you have two direction actions (one forward/backward and one left/right) and one attack action, you would need to set the Space Size to 3, and your OnActionReceived would look something like

    Code (CSharp):
    1. public override void OnActionReceived(float[] actions)
    2. {
    3.   var forwardAction = actions[0];
    4.   var sideAction = actions[1];
    5.   var attack = actions[2] > 0;
    6.   // do stuff with the values
    7. }