Blueprints now support declaring an integer variable as a bitmask. This allows individual mask bits (flags) to be set and unset through the editor rather than having to manually enter values. Additionally, _Blueprint Enumerations _can also be declared as a Bitmask Flags type for use as explicit bitflag identifiers.
Creating Bitmask Variables
Any integer variable can also be created and declared as a bitmask when working with a Blueprint Class in the Blueprint Editor.
-
Create a Blueprint Enumeration that is also a bitflag enumeration type by toggling the Bitmask Flags attribute on in the Blueprint Enumeration Editor. You could also use an existing bitflag enumeration type that was set up in C++ using the
BitmaskEnum=
metadata. -
In your Blueprint, create an integer variable and then enable the Bitmask attribute in the Details panel.
This equates to the
Bitmask
metadata in C++ code. -
Select your Blueprint Enumeration (or existing bitflag enumeration) in the Bitmask Enum dropdown menu in the Details panel.
-
On the variable's Set node, you will be able to use the dropdown to select the variable's value. You can also set the default variable value in the Details panel after compiling the Blueprint.
Constructing Bitmasks at Runtime
Bitmask literals can be created in a Blueprint Class graph via the Make Bitmask node.
-
Right-click in your graph and type "Make Bitmask" in the context menu.
-
Select Make Bitmask.
-
Click on the node, then look at the Details panel. Use the Bitmask Enum dropdown to change the enumeration type that is associated with the bitmask. As with integer variables defined within the class, only enumeration types with the Bitmask Flags attribute enabled will be listed in the dropdown.
-
On the node, you can now select the Bitmask to create.
Bitmask Usage
Bitmasks are treated the same as an integer value in a Blueprint Graph. Bitmask integer output pins can be connected to any input pin that accepts an integer value; this will usually be the bitwise OR, AND, XOR and NOT operations.
In this first example, a single Make Bitmask node is passed to a Bitwise XOR node to toggle the Red flag stored in Target Color Flags. The enumeration storing the color values would also have the Bitmask Flags attribute toggled on.
In the second example, the Select node, Bitwise NOT, and Bitwise AND nodes all take integers as inputs, so they can be used to select one of three sets of colors, toggle them, and then save that result out to the Target Color Flags bitmask.