Announcement

Collapse
No announcement yet.

BitMask Tutorial?

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

    BitMask Tutorial?

    Im wondering if someone can help me understand bitmasks in a simple way. i've never used them and i tried looking at the API but i just dont understand it.. I understand how to make them. I just dont understand how to USE them. I made the enum and everything. I have 2. One for faction type of my character and the other for movement calling such as attacking, dodging, sprinting, etc. I tried to use my flag in an if statement and its not working. nor do i know how to set the flag to the proper number. Any help is appreciated, thank you!
    from the tutorial, this is what i came up with :
    UENUM(BlueprintType, meta = (Bitflags))

    enum class EMovementCallFlags : uint8

    {



    Dodging,

    Sprinting,

    Attacking,

    Blocking,

    };

    ENUM_CLASS_FLAGS(EMovementCallFlags)
    UPROPERTY(EditAnywhere, Category = "MovementCalls", meta = (Bitmask, BitmaskEnum = "EMovementCallFlags"))

    uint8 MovementCallFlags;

    #2
    Bitflags aren't UE4 specific, I'd just google for a good C++ Bit Operators tutorial and run through that. They're simple, but rather difficult to describe in just a few lines.

    As for your questions:

    To turn a flag on:
    Code:
    MovementCallFlags |= EMovementCallFlags::Dodging;
    To turn a flag off:
    Code:
    MovementCallFlags &= ~EMovementCallFlags::Dodging;
    To test for a flag:
    Code:
    if (MovementCallFlags & EMovementCallFags::Dodging)
    {
       // Flag is true.
    }
    Able Ability System - A high performance, robust ability system for UE4. Now Available!

    Comment


      #3
      ExtraLifeMatt Hey! Thank you for replying i will definitely look this up, i appreciate it!

      Comment

      Working...
      X