Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Discrete Action Mask doesn't work with List

Discussion in 'ML-Agents' started by ilaydanil, Jun 6, 2020.

  1. ilaydanil

    ilaydanil

    Joined:
    May 17, 2020
    Posts:
    20
    This code works perfectly.

    Code (CSharp):
    1.   public override void CollectDiscreteActionMasks(DiscreteActionMasker actionMasker)
    2.     {
    3.          actionMasker.SetMask(0, new int[4] { 0, 1, 2, 3 });
    4.     }

    But when I try this code it doesn't give any error but OnActionReceived completely ignores the masks. I don't understand it.

    Code (CSharp):
    1. public override void CollectDiscreteActionMasks(DiscreteActionMasker actionMasker)
    2.     {
    3.         int targetMask = 4;
    4.         List<int> maskList = new List<int>();
    5.         for (int i = 0; i < targetMask; i++)
    6.         {
    7.             maskList.Add(targetMask);
    8.         }
    9.         actionMasker.SetMask(0, maskList);
    10.     }
    I also tried to use maskList.ToArray yet it didn't work. Why is that?
     
  2. mbaske

    mbaske

    Joined:
    Dec 31, 2017
    Posts:
    473
    Should probably be maskList.Add(i); in line 7, not maskList.Add(targetMask);
     
  3. ilaydanil

    ilaydanil

    Joined:
    May 17, 2020
    Posts:
    20
    Yeah you were right, my bad