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
- [Mobile] Player Crash on scripting_invoke_profiler_begin when the built Player Scene has an empty UIDocument and is built on IL2CPP
- Unnecessary Warnings are logged when running Player with -batchmode -nographics
- [Android] [iOS] Application silently crashes when creating and setting up Textures2D in large amounts
- Some VFX Window Panels close on entering Play mode
- VFX Graph using Redo action for Move and Connect node results in an unknown input value
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
}