Bitmask Blueprint Variables

Blueprint integer variables can be declared as bitmasks to store binary flags in a more compact fashion.

Choose your operating system:

Windows

macOS

Linux

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 .

  1. 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.

    image alt text

  2. In your Blueprint , create an integer variable and then enable the Bitmask attribute in the Details panel.

    image alt text

    This equates to the Bitmask metadata in C++ code.

  3. Select your Blueprint Enumeration (or existing bitflag enumeration) in the Bitmask Enum dropdown menu in the Details panel.

    image alt text

  4. 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.

    image alt text

Constructing Bitmasks at Runtime

Bitmask literals can be created in a Blueprint Class graph via the Make Bitmask node.

  1. Right-click in your graph and type "Make Bitmask" in the context menu.

  2. Select Make Bitmask .

    image alt text

  3. 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.

    image alt text

  4. On the node, you can now select the Bitmask to create.

    image alt text

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.

image alt text

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.

image alt text

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss