Download

What does "FBTNodeBPImplementationHelper::AISpecific" do?

I want to make an AI task in C++, And I read code of “BTTask_BlueprintBase.cpp” to learn how to do it, I noticed a variable named AISpecific in FBTNodeBPImplementationHelper. It is a const, and it = 1<<1.
Pic0
In BTTask_BlueprintBase, When Call “AI” function, it will use this variable, But I can’t understand how it woek.


It work fine in BulePrint, But I use it in C++, It always = 2.
So , what is this? can I delete it like this?

Now I deleted it, Nothing happend, And I want to know it more.

Look up bit masking, it’s a way of using all the bits in a larger type (like int32) to store multiple booleans. One “&” is bitwise-AND, the value you’re looking at is const and will always be 2 (<< is binary left shift). You could think of the code as doing RecieveExecuteImplementations.AISpecific == true.

Thanks first.
As you said, I know it always be 2, so what meaning of this? I can delete it and will No any logical change right? so it is useless?

And I’m confused why engine have bool & always true code

Numbers are stored in binary on the PC; here we’re actually treating these values as arrays of bits rather than as numbers. AISpecific is a “bit mask”, and the “&” operator is a bitwise-AND. If ReceiveExecuteImplementations has the second bit set, then ReceiveExecuteImplementations & AISpecific will be 2, which is non-zero (true), otherwise it’ll be zero (false). ReceiveExecuteImplementations can have lots of bits set besides just the second bit, but this code only tests the second bit because that’s the only bit set in the AISpecific mask.

To understand left-shift: 1 << 1 is 2, 1 << 2 is 4, 1 << 3 is 8 and so on. In binary it’s more clear as that’d be 0001, 0010, 0100… the << operator literally shifts the binary digits left.

To understand &: 1101 & 0010 is 0 because all of the bits are different, but 0111 & 0010 is 0010 because the second bit (from the right) is set in both inputs.