Make Bitmask returns incorrect value

Referring to this (unanswered) question, I’m escalating the issue to what I believe is a bug. Bitmasks created in C++ and via blueprint return different values, with the Blueprint bitmask being incorrect.

Steps to reproduce:
In a C++ actor, define a bitmask as

UENUM( BlueprintType, meta=(Bitflags) )
enum ETest
{
  BITFLAG1 = 1  UMETA( DisplayName = "BitFlag 1" ),
  BITFLAG2 = 2  UMETA( DisplayName = "BitFlag 2" ),
  BITFLAG3 = 4  UMETA( DisplayName = "BitFlag 3" )
};
ENUM_CLASS_FLAGS( ETest )

UCLASS()
class TEST_API ATestActor : public AActor
{
  GENERATED_BODY()

public:
  ATestActor();

  UPROPERTY( BlueprintReadWrite, Category = "Test", meta=(Bitmask, BitmaskEnum=ETest) )
  int32 TestBitmask;
};

In the constructor, set the first and third bits of the mask. The integer value of this mask should total 5 with these two bits set:

ATestActor::ATestActor()
{
  TestBitmask = 0;
  TestBitmask |= ETest::BITFLAG1;
  TestBitmask |= ETest::BITFLAG3;
}

Next, create a new Blueprint derived from this actor. In the Begin event, get the value for TestBitmask and print the value on screen (should display 5, as expected).

Now add a Make Bitmask node, set its Bitmask Enum value to ETest and set BitFlag 1 and BitFlag 3. As this replicates the C++ created bitmask, I expect the return value to be 5 as well. However, printing the return value gives me 18.

Any bitwise logic operations performed on this incorrect value will yield unexpected results.

Hey Morni-

It appears that the value of the bit is being doubled before the operation is executed. I have entered the bug report UE-32816 for investigation.

Cheers

Doug Wilson

Hi, what happened to this issue? I can’t find it among issues.
I’ve got similar issue when I’m setting first bitmask enum value to 0x01 and get its value as 0x02 instead. If I set enum values starting from 0x02 it works fine.

Update: Also I’ve added “None = 0x00” and it became 0x01. So I guess it adds some additional value to enum before user specified, probably similar as it does with max value.

Update: If you set no actual values to enum items, you get 0 for no flags set, 1 for the first flag, 2 for second flag, 4 for third etc. So it works as it should.

Hey Anry-

You can now vote on and view the status of this issue here (Unreal Engine Issues and Bug Tracker (UE-32816) ).

Hey Doug! Thanks a lot!

Hey Anry -

Try setting up and operating on your Bitflags like I’ve posted in my answer here:

https://answers.unrealengine.com/questions/489492/c-bitmask-enums-appear-to-be-offset-by-1.html

Using the macros I’ve provided you should be able to produce the results you are looking for.

Hi, Danny, thank you.