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
- Missing space in Cache Server documentation link tooltip in Project Settings
- Android soft keyboard's arrows and select tools do not have visual feedback when Hide Mobile Input is enabled
- No padding in the UI Toolkit Project Settings
- Unity Perforce: Connection is extremely slow or times out when "Scan Local Packages on Connect" is enabled in Version Control while the project has many local packages
- Not compatible Style Sheets can be selected in the TSS files under "Style Sheets"
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
}