And the compiler returns an error that I’m boxing the value type ColliderFlags. (???).
I had this problem before when I created extension methods for ColliderFlags that had a (this ColliderFlag flag, ColliderFlag otherFlag) parameters, so it said I was boxing the flag, of course, by doing “this”, converting the other flag to an object…
Well. Seems like when I removed those extension methods and started doing it with the native method HasFlag, the error kept showing up.
or EVEN testing by hand
(collider.Flags & ColliderFlags.SelfHit) != 0
Also returns a compilation error.
But ONLY on one of the places it is used in. If you comment one occurrence, it happens in another place.
Also dissapears if I remove the [Flags] attribute.
Sadly, the .NET HasFlag method uses boxing. (System.Enum is a class.)
I usually put together some extension methods to cover up these API holes. Something to the tune of:
/// <summary>
/// Checks if this enum value contains all the bits of the given flags.
/// If the flag is zero, this method returns true.
/// </summary>
public static bool HasAllFlags<TEnum>(this TEnum self, TEnum flag) where TEnum : unmanaged, Enum
{
ulong enum_ulong = 0;
ulong flag_ulong = 0;
UnsafeUtility.As<ulong, TEnum>(ref enum_ulong) = self;
UnsafeUtility.As<ulong, TEnum>(ref flag_ulong) = flag;
return (enum_ulong & flag_ulong) == flag_ulong;
}
/// <summary>
/// Checks if this enum value contains any of the bits of the given flags.
/// If the flag is zero, this method returns false.
/// </summary>
public static bool HasAnyFlags<TEnum>(this TEnum self, TEnum flags) where TEnum : unmanaged, Enum
{
ulong enum_ulong = 0;
ulong flag_ulong = 0;
UnsafeUtility.As<ulong, TEnum>(ref enum_ulong) = self;
UnsafeUtility.As<ulong, TEnum>(ref flag_ulong) = flags;
return (enum_ulong & flag_ulong) != 0;
}
/// <summary> Checks if this enum value is equal to the other enum. </summary>
public static bool Is<TEnum>(this TEnum self, TEnum other) where TEnum : unmanaged, Enum
{
ulong enum_ulong = 0;
ulong other_ulong = 0;
UnsafeUtility.As<ulong, TEnum>(ref enum_ulong) = self;
UnsafeUtility.As<ulong, TEnum>(ref other_ulong) = other;
return enum_ulong == other_ulong;
}
(The enum values are written to an ulong before comparison to safely accomodate for the largest possible enum backing type size. Not sure if I’m overdoing it with trying not to anger the Stack Gods here…)
Uhhhh, sounds like it might be some sort of a weird Burst caching bug. If you can find a repro, I’m sure the Burst guys would love a report of that. Otherwise, try nuking your your Library/BurstCache folder.
I tried creating extension methods, but they failed too because I thought they had a boxing problem because of the “This” parameter…
That’s where all started. Then I used HasFlag, and failed again. Then I did it manually and failed too.
I did what you said, deleted the BurstCache folder. No problem with the “by hand” method.
Now I made the extensions without HasFlag again and doesn’t fail.
So for some reason using HasFlag affected the cache somehow and was stuck there even though there was no error anymore.
[EDIT] Tried to reproduce on a single file project and I got the boxing problem, but when I remove it it doesn’t stay. So I can’t reproduce this weird bug.