Bitmask Help

Hey,

Im totally new to using bitmasks. This might not be the right way to use them but it seems like a nice tidy way to present artists with the choice. I want to use bitmask flags instead of 5 bools to filter what random meshes can be spawned. IE you can tick the few you want it to choose from.

I have the bitmask enum set up for mesh A,B,C,D. I want to get which enum values are flagged, and then randomly choose one of them to spawn.

Could anyone advice how to set this up, either that or tell me this is a terrible usecase and I should do something else.

Cheers.

By way you compose this blueprint, i think easiest option for you would be creating array of actor classes and randomly picking one item in array (Plug to “Max” pin size of array subtracted by 1)

I could do this but it doesnt quite fill what Im trying to achieve, I want to allow the user to filter the option of spawned meshes, so with the bitmask you can tick A,B,C and leave D unticked. Now the blueprint will only try to randomly spawn a,b or c and ignore D entirely. It can be done with bools and branches, but bitmasks seemed tidier and Id like to learn them.

Blueprints are not really goot for bitmask, UE4 don’t use them much.

Here general how bitmasks work:

Integers need to be power of 2 to make it work. 1,2,4,8,16,32,64,128 etc. integers in blueprints are 32-bit there also Byte type which is 8-bit.

Each power of 2 number represent is specific bit, you add them up to set specifics bits to 1 and you subtract that number to set it to 0. so let say we have 8-bit integer 00000000, if you do 2+4+32+128 it will be 166 which in binary is 10100110 then let say sunstract 4 from 166, it will be 162 it will cause 3rd bit to 0, and it will be 10100010

Now how to check if specific bit is set? you use it with AND operator (which is equivalent of AND gate), which in most languages is “&” blueprint has it too

let say we want to check 4nd bit is set to which will be number 8, so you do Bitmask & 8 If it return 0 it means bit is 0 if it’s return the bit number (in this case 8) or something else it’s means it’s set to 1

Good answer, makes it a lot clearer when you break it down like that. Thanks