Developer Notes

This is actually as-designed behavior - the enum values are currently assumed to be flag indices and not actual flag mask values. That is, the editor will compute (1 << N) where N is the value of the enum. This is consistent with how user-defined enums work on the editor side.

Can see how it would be useful to be able to designate native C++ enums as literal mask values though, especially when used alongside ENUM_CLASS_FLAGS().

Note for testing: After the fix is applied, modify the line above (in MyActor.h) as follows:
UENUM(BlueprintType, meta = (Bitflags, UseEnumValuesAsMaskValuesInEditor="true"))

Description

When a custom enum is used as the Bitmask Enum of a Make Bitmask node, the value returned does not match the expected value

Steps to Reproduce
  1. Open UE4 Editor
  2. Add Code to project based on Actor (MyActor)
  3. Add the following code to MyActor
    • .h
      UENUM(BlueprintType, meta = (Bitflags))
      enum ETest
      {
      	BITFLAG1 = 1 UMETA (DisplayName = "BitFlag 1"),
      	BITFLAG2 = 2 UMETA(DisplayName = "BitFlag 2"),
      	BITFLAG3 = 3 UMETA(DisplayName = "BitFlag 3"),
      	BITFLAG4 = 4 UMETA(DisplayName = "BitFlag 3"),
      };
      
    • .cpp (in Constructor)
      	TestBitmask = 0;
      	TestBitmask |= ETest::BITFLAG1;
      	TestBitmask |= ETest::BITFLAG3;
      
  4. Compile
  5. In editor, create blueprint based on MyActor
  6. Add Get TestBitmask node
    • From return pin, create ToString(int) node
  7. From BeginPlay execution pin, add Print String node
  8. Wire ToString node to Print String node
  9. Create duplicate of ToString and Print String nodes
  10. Right click and create Make Bitmask node
  11. With Bitmask node selected, set Bitmask Enum to ETest
  12. Check BitFlag1 and BitFlag3
  13. Wire Make Bitmask node to duplicated ToString node
  14. Wire Print String execution to the duplicated Print String
  15. Add instance of MyActorBP to the level and PIE

Result:
First Print String (from code) prints 5 as expected. Second Print String (Make Bitmask node) prints 18.

Expected:
Number 5 gets printed to the screen twice.

Have Comments or More Details?

Head over to the existing Questions & Answers thread and let us know what's up.

8
Login to Vote

Fixed
ComponentUE - Gameplay - Blueprint
Affects Versions4.12.4
Target Fix4.16
Fix Commit3347562
Main Commit3358685
CreatedJul 5, 2016
ResolvedMar 15, 2017
UpdatedSep 13, 2023
View Jira Issue