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
- "IndexOutOfRangeException" and "NullReferenceException" are thrown and Element disappears from UI Builder when undoing rename of element in "Open Instance in Context" menu
- Select Scriptable Object window freezes and becomes unresponsive when currently opened UXML Template is selected for binding's Data Source
- [Linux] “ReleaseButton expects buttonId >= 0” error is thrown when importing Assets via drag and drop
- Asset gets unselected and added Subgraphs list item is not undone when performing Undo in Heatmap with Default Values asset Inspector
- Black square “shadow” artifacts visible when using Screen Space Reflections without maximum smoothing
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
}