Search Issue Tracker
By Design
Votes
0
Found in
2019.4
2020.3
2021.2
2022.1
2022.1.0a15
Issue ID
1378512
Regression
No
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
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- [Dragon Crashers] Build fails in U6
- [Dragon Crashers] 4 Shader error messages on import
- [Dragon Crashers] Readme text is white on light grey
- Cursor stays in front of the first character when entering text in the TextMeshPro field
- Searching in Hierarchy causes unwanted component calls
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:
[Flags]
public enum MyEnum
{
First = 1,
Second = 2,
Third = 4,
Fourth = 8,
Fifth = 16,
Sixth = 32
}