Announcement

Collapse
No announcement yet.

How to use bitmask blueprint enums?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to use bitmask blueprint enums?

    Suppose I create a bitmask blueprint enum, with values ValA, ValB, ValC and ValD.

    Now, I want to keep a bitmask variable that contains zero or more of these bits set.

    I can't figure out how I'm supposed to do this.
    There is something called a bitmask integer.
    I can specify my enum as the "type" of that bitmask.
    There is a "Set" operation for this bitmask where I can choose one of the various bit values.

    However, if I already have one of the enum values, how do I set that into the given variable?
    I can convert-byte-to-int, and then route that into the bitmask-set-node, but the value of "ValD" is actually 3, not 8 as I would expect.

    Does "Set" for a bitmask value do the appropriate left-shift for me?
    It doesn't seem like it to me. The value of the bitmak integer is "3" after the SET, not "8."

    Is casting enum byte to integer what I should do?

    It would seem like enum bitmask "Union" and "Intersect" and "Disjoint" operations would be great Nodes to have.
    "I have these bits, add them to those other bits over there." (OR)
    "I have these bits, remove them from those other bits over there." (AND NOT)
    "I have these bits, only keep those other bits over there that match." (AND)

    #2
    Maybe I'm just misunderstanding blueprint bitmask enums. They don't seem to generate any values different from a regular enum.
    I e, checking the "bitmask" checkbox does not change the values to 1, 2, 4, 8, 16 ... -- I still get 0, 1, 2, 3, 4.

    That being said, there are no bit shift operators in the Blueprint math library, so I'll have to create those for myself.

    Comment


      #3
      See if this helps:

      Click image for larger version

Name:	Untitled.png
Views:	1
Size:	55.8 KB
ID:	1123777

      Also: https://docs.unrealengine.com/latest...ables/Bitmask/
      Last edited by Everynone; 02-22-2017, 02:13 PM.

      Comment


        #4
        No, that's not the problem.
        My problem is that I want to pipe which bit to set into the left input of the SET operation.
        But, the actual values of the enum types are not bit values, but just sequential integers.
        I need to create the correct value to put in by left-shifting by the value of the enum.
        Except there is no left-shift operator in the Blueprint system!

        Click image for larger version

Name:	bitmask-enum.jpg
Views:	1
Size:	85.7 KB
ID:	1123828

        Click image for larger version

Name:	byte-to-bitmask.jpg
Views:	1
Size:	273.3 KB
ID:	1123829

        Comment


          #5
          I believe that flagging enum with bitmask flag does not change the behaviour of the enumerator itself. It does allow you to use that enum as a bitmasked int, though. Consider the following:

          Click image for larger version

Name:	Untitled.png
Views:	1
Size:	49.8 KB
ID:	1123830
          Last edited by Everynone; 02-23-2017, 02:03 PM.

          Comment


            #6
            So, you're suggesting that the intended use case is that, every time I want to use a bitmask enum to specify which flag I want to set or clear, I have to create a "select" node and manually set up each of the values within the bitmask?
            That's ... not optimal! Maybe I should send my byte-to-bitmask node back as a pull request !

            Comment


              #7
              I merely suggest you add it to the list of blueprint awkwardness.

              edit: [MENTION=2525]jwatte[/MENTION][/MENTION] - I think the whole concept with blueprint usage revolves around not using the enumerator:

              Click image for larger version

Name:	Untitled.png
Views:	1
Size:	35.2 KB
ID:	1123846

              I think that's the closest you'll get to what you need in pure BP. But since you're not limited to that...
              Last edited by Everynone; 02-23-2017, 05:18 PM.

              Comment

              Working...
              X