Search Issue Tracker

By Design



Found in






Issue ID




EditorGUILayout.EnumFlagsField sometimes marks incorrect flags when trying to enable them



How to reproduce:
1. Open the user's attached "EnumTest" project
2. Select the "Main Camera" GameObject in the Hierarchy
3. Select the "Getters" field in the "New Behaviour Script" Component in the Inspector
4. Select any Enum value
5. Observe the selected Enums in the field

Expected result: Only selected Enums are marked in the "Getters" field
Actual result: Sometimes different or additional flags are marked

Reproducible with: 2019.4.33f1, 2020.3.23f1, 2021.2.4f1, 2022.1.0a16

  1. Response avatar

    Resolution Note:

    The flags are using shared bits.

    By default, they are assigned the following values
    First = 0,
    Second = 1,
    Third = 2,
    Fourth = 3,
    Fifth = 4,
    Sixth = 5

    If we look at this as bits we get

    First  = 0000,
    Second = 0001,
    Third  = 0010,
    Fourth = 0011,
    Fifth  = 0100,
    Sixth  = 0101

    You can see that some share the same bits.
    In the bug, we have Sixth which has the flags 0101. As you can see Fifth and Second also have these flags so they are shown in the menu as highlighted.

    To fix this the enums should be given unique bits like so:

    public enum MyEnum
        First = 1,
        Second = 2,
        Third = 4,
        Fourth = 8,
        Fifth = 16,
        Sixth = 32

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.