Enum Flags In Unity and C#
Enum Flags are a C# feature that allow for multiple enum values to be applied to a single enum variable.
Enum Flags allow for multiple enum values to be applied to a single enum variable. This feature is a part of C#’s System namespace.
First, add the Flags attribute to your enum list:
This will allow multiple Enum constants to be selected, as well as adding an “Everything” option which selects all states:
However, just this is not quite enough. As it currently is, choosing the states you want will not necessarily select them in the way you intended.
Using the Flags attribute indicates that the Enum can be treated as something called a Bit Mask.
A bit mask is, essentially, an integer value in which several binary properties (yes/no) are independently stored in its bit. -Source
That is because the Enum uses integer index IDs behind the scenes to identify the different states. These IDs are also not just 0,1,2,etc. They are
By manually assigning the IDs in Power-Of-Two form, it allows multiple options to be chosen at once.
Once these are manually defined, the Enum can be compiled and interpreted in the desired way, resulting in: