# Make Bitmask returns incorrect value

**URL:** <https://forums.unrealengine.com/t/make-bitmask-returns-incorrect-value/362752>\
**Category:** Blueprint\
**Tags:** unreal-engine, Blueprint, CPP, question\
**Created:** [July 2, 2016, 4:51pm UTC](https://forums.unrealengine.com/t/make-bitmask-returns-incorrect-value/362752 "2016-07-02T16:51:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Morni](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Morni](https://forums.unrealengine.com/u/Morni)\
**Post date:** [July 2, 2016, 4:51pm UTC](https://forums.unrealengine.com/t/make-bitmask-returns-incorrect-value/362752/1 "2016-07-02T16:51:32Z")

</div>

Referring to [this](https://answers.unrealengine.com/questions/440190/bitmask-enum-declaration-in-412-whats-missing.html) (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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [July 5, 2016, 9:40pm UTC](https://forums.unrealengine.com/t/make-bitmask-returns-incorrect-value/362752/2 "2016-07-05T21:40:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Anry\_Narleyn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anry\_Narleyn](https://forums.unrealengine.com/u/Anry_Narleyn)\
**Post date:** [September 4, 2016, 3:52pm UTC](https://forums.unrealengine.com/t/make-bitmask-returns-incorrect-value/362752/3 "2016-09-04T15:52:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [September 6, 2016, 8:15pm UTC](https://forums.unrealengine.com/t/make-bitmask-returns-incorrect-value/362752/4 "2016-09-06T20:15:08Z")

</div>

Hey -

You can now vote on and view the status of this issue here ([Unreal Engine Issues and Bug Tracker (UE-32816)](https://issues.unrealengine.com/issue/UE-32816) ).

---

<div class="post-metadata">

**Author:** ![Anry\_Narleyn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anry\_Narleyn](https://forums.unrealengine.com/u/Anry_Narleyn)\
**Post date:** [September 6, 2016, 9:07pm UTC](https://forums.unrealengine.com/t/make-bitmask-returns-incorrect-value/362752/5 "2016-09-06T21:07:44Z")

</div>

Hey ! Thanks a lot!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e0b6b045](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e0b6b045](https://forums.unrealengine.com/u/anonymous_user_e0b6b045)\
**Post date:** [September 22, 2016, 7:20pm UTC](https://forums.unrealengine.com/t/make-bitmask-returns-incorrect-value/362752/6 "2016-09-22T19:20:16Z")

</div>

Hey -

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](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.

---

<div class="post-metadata">

**Author:** ![Anry\_Narleyn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anry\_Narleyn](https://forums.unrealengine.com/u/Anry_Narleyn)\
**Post date:** [August 11, 2017, 2:07pm UTC](https://forums.unrealengine.com/t/make-bitmask-returns-incorrect-value/362752/7 "2017-08-11T14:07:35Z")

</div>

Hi, Danny, thank you.
