Count number of true booleans in array

Hi everyone,

Is there a way that you can count the number of true variables in an array of booleans? I want to have an updating int variable that returns 0 if all false, 1 if 1 true, 4 if 4 true etc. Is this possible with blueprints? I’ve tried a ForEachLoop node and a length node but those don’t allow you to actually test the variables in the array, just simply get all of them.

Thanks for your help!

It was worded weirdly. He can easily replace the IntArray with a bool array and it would work exactly the same.

you could try something like this

where the for each loop gets the value of the array at every index (1 the first pass, 2 the second, so on…) then this converts the bool into integer where 1 = true and 0 = false and if the value is equal to 1 then it adds up the count of true bools.

Another way that doesn’t involve conversion to integer so it’ll be more intuitive is this

he was looking for a bool array not an integer array… thanks for the logic portion though my initial attempt was messy I was unaware of the existence of the branch node

Why not just use the array element in the branch?

Ah thank you very much, that does the trick! I didn’t know you could use the get node to compare more than one with foreachloop.

thatd work fine too