[IL2CPP] Cannot Convert 'Nullable<Enum>' to 'int' During Android Build

Issue When building for Android with IL2CPP, the following error may occur:

This happens when calling .HasFlag() on a Nullable<Enum>.

Cause This is a known issue in Unity 2021, where Enum.HasFlag() does not compile correctly under IL2CPP when used with nullable enums. See Unity’s official issue tracker: 👉 https://issuetracker.unity3d.com/issues/il2cpp-fails-code-conversion-for-enum-dot-hasflag-case

Solution Upgrade your Unity version to 2022.1 or later, where this bug has been fixed.

Last updated