Search Unity

Bug Burst error BC1020 for Flags

Discussion in 'Entity Component System' started by YourWaifu, Apr 21, 2022.

  1. YourWaifu

    YourWaifu

    Joined:
    Oct 4, 2015
    Posts:
    45
    > (0,0): Burst error BC1020: Boxing a valuetype `Components.FooFlags` to a managed object is not supported

    Why there is no transparency compiling for flags enum
    I can use constants, but its not so convenient

    Components.FooFlags:

    Code (CSharp):
    1.  
    2. [Flags]
    3. public enum FooFlags: int
    4. {
    5.     DETACHED = 1 << 1,
    6.     READY = 1 << 2
    7. }
    8.  
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,848
    "boxing to managed object" sounds to me as if you are adding a FooFlags variable to a managed object such as a List or Dictionary where boxing occurs (collections only store reference types, therefore value types like enums are boxed into an object).

    can you post the code that uses FooFlags?
     
  3. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    883
    Maybe you are using flags.HasFlag? This method generates garbage and uses boxing.
     
  4. YourWaifu

    YourWaifu

    Joined:
    Oct 4, 2015
    Posts:
    45
    Yes, i using HasFlag

    It is unclear to me why burst does not know how to work with such code
     
  5. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    Because Unitys current version of the system library's HasFlags looks like this.

    Code (CSharp):
    1. public bool HasFlag(Enum flag)
    2.     {
    3.       if (flag == null)
    4.         throw new ArgumentNullException(nameof (flag));
    5.       return this.GetType().IsEquivalentTo(flag.GetType()) ? this.InternalHasFlag(flag) : throw new ArgumentException(Environment.GetResourceString("Argument_EnumTypeDoesNotMatch", (object) flag.GetType(), (object) this.GetType()));
    6.     }
    which is very not burst usable.
     
    Harry-Wells likes this.
  6. Arnold_2013

    Arnold_2013

    Joined:
    Nov 24, 2013
    Posts:
    284
    YourWaifu and DreamingImLatios like this.
  7. YourWaifu

    YourWaifu

    Joined:
    Oct 4, 2015
    Posts:
    45
    Damn...
    They could make a plug for that... ̶p̶u̶r̶p̶o̶s̶e̶ ̶o̶f̶ ̶t̶o̶o̶l̶ ̶i̶s̶ ̶t̶o̶ ̶e̶a̶s̶e̶ ̶t̶h̶e̶ ̶f̶a̶t̶e̶ ̶o̶f̶ ̶d̶e̶v̶e̶l̶o̶p̶e̶r̶,̶ ̶n̶o̶t̶ ̶t̶o̶ ̶f̶o̶r̶c̶e̶ ̶h̶i̶m̶ ̶t̶o̶ ̶d̶o̶ ̶k̶l̶u̶g̶e̶ ̶.̶.̶.̶

    Solution from @Arnold_2013 is good for me, thanks.