Search Unity

Question Self-play switching team ids leads to action masking bug

Discussion in 'ML-Agents' started by Rany_AN, Jul 1, 2021.

  1. Rany_AN

    Rany_AN

    Joined:
    Apr 24, 2021
    Posts:
    33
    Hello,

    I have a problem using self-play which happens when I switch team id from 0 to 1 on an agent and 1 to 0 on the other agent that leads to one of them ignoring action masking.

    How is this possible?
    (Why is action masking affected by self-play agent's team ids)

    Could it be a problem from my side?
     
  2. christophergoy

    christophergoy

    Joined:
    Sep 16, 2015
    Posts:
    735
    Hi, could you give us more information about how you are doing action masking?
     
  3. Rany_AN

    Rany_AN

    Joined:
    Apr 24, 2021
    Posts:
    33
    For instance, not allowing the agent to move to the right.

    Code (CSharp):
    1. public override void WriteDiscreteActionMask(IDiscreteActionMask actionMask){
    2.         Collider2D hitCollider = Physics2D.OverlapBox((Vector2)gameObject.transform.position + new Vector2(1, 0), new Vector2(0.15f, 0.15f), 0f, colliderLayerMask);
    3.         if (hitCollider)
    4.         {
    5.             //Debug.Log(gameObject.name + " Hit : " + hitCollider.name);
    6.             if (hitCollider.CompareTag("Enemy") || hitCollider.CompareTag("Obstacle"))
    7.             {
    8.                 //Debug.Log(gameObject.name + " masking action 5");
    9.                 actionMask.SetActionEnabled(0, 5, false);
    10.             }
    11.         }
    12. }
    13.  
    Problem:
    Agent 1 attached to game object 1 with team id = 0 will ignore the action mask and move right over a collider.
    Agent 2 attached to game object 2 with team id = 1 will respect the action masking.

    If agent 1 attached to game object 1 switches team id = 1, and agent 2 attached to game object 2 switches team id = 0, both agents will respect action masking.

    Update: No matter which team ID I give to agent 2 attached to game object 2, it will always ignore action masking!

    I'm really short on time if anyone could help!
     
    Last edited: Jul 7, 2021
  4. Rany_AN

    Rany_AN

    Joined:
    Apr 24, 2021
    Posts:
    33
  5. christophergoy

    christophergoy

    Joined:
    Sep 16, 2015
    Posts:
    735
    I'm talking with our research team now to see if we can diagnose and solve this problem.
     
  6. christophergoy

    christophergoy

    Joined:
    Sep 16, 2015
    Posts:
    735
    Is your second agent on the same physics layer and everything? We are still looking into where this might be an issue on our end, but haven't come up with anything yet.
     
  7. Rany_AN

    Rany_AN

    Joined:
    Apr 24, 2021
    Posts:
    33
    Yes it is, I sent you the link to another thread with the same problem.
     
  8. christophergoy

    christophergoy

    Joined:
    Sep 16, 2015
    Posts:
    735
    Are you willing to share your project with us so we can debug it ourselves? We are unable to reproduce this behavior.
     
  9. R0b_g

    R0b_g

    Joined:
    Jul 14, 2019
    Posts:
    3
    hey, I'm probably way to late but try setting
    threaded: false
    in the .yaml/configuration file, it worked for me
     
  10. Rany_AN

    Rany_AN

    Joined:
    Apr 24, 2021
    Posts:
    33
    Sorry for the late reply, but I changed the code long ago so that I wouldn't have to deal with this problem.
     
  11. Rany_AN

    Rany_AN

    Joined:
    Apr 24, 2021
    Posts:
    33
    Thank you so much. Unfortunately, I'm not working on the project anymore. Maybe I will resume later.
    Thanks for letting me and others who have the same problem know.
     
    R0b_g likes this.