Where can I store boolean variables? (or a boolean array)

For example, player states. I’ve tried using enum but it only allows 1 state of a variable and you need to make 2 different states.

With enums, you can do it like: Player has power up / Player has not power up

But that kind of logic is better off with using booleans. I’m using boolean variables at the moment but there’s a lot of them and I was wondering if I can somehow store them in an array and then call/set them later at my convenience.

Thanks.

Well I think the character blueprint would be a good place to store them. When you say that you want to set them later at your convenience do you mean like use them after you change levels?

No, I just want to know the best way to make use of booleans. Should I fill my character BP with boolean variables or can I use something like an ENUM to store them and then access them easier?

This. I like it. I’m gonna fiddle around and see if it’s worth the hassle.

On the other hand, it seems like there isn’t such a thing as storing boolean variables in an array.

I’m not sure what you mean by “there isn’t such a thing as storing boolean variables in an array”.

There definitely are arrays available in the engine. In blueprints, you just have to press an icon next to the variable to make it into an array.

Not sure if it is what you want exactly, but I would suggest looking into using an Enumerator that has the bit mask set.
This way when you declare an integer, you can set it to being a bitmask and then assign the enumerator as the type for the field.

This works rather nicely but there are a couple slight annoyances regarding the ui display of them across saves and parent / child blueprints.

But in most cases at the configuration UI level you can use the drop down checkmark for setting multiple bits in your integer.

The good feature is that as an bit mask you can enable multiple states in one variable.

You just write a nice access API for doing the set / get / test stuff so its cleaner and your good to go.

Well yea? you just click ‘array’ beside where you have defined which type of variable you want? that will give you an array.

Bits are better :stuck_out_tongue:

Yeah but you can’t define boolean variables within the array like you can with an enumeration. You can only index them from 0.

And what’s the problem with accessing those booleans through index?

Edit: You know that an enumeration is basically an index from 0 to n, right?

Well, with enumartions, you can only have 1 state/index at a time but I wanted an array with multiple states that checks which one of them is true/false. And then a node that checks which one of those states is true/false so it will fire respective events based on the states. Player states for example. With enumerations you can only have let’s say “In air” at a time but you can’t have “In air” + “Running” + “Has power up” + “Is X key pressed?” etc…

I see what you mean now. However, personally I wouldn’t handle the state of the player like that. Usually if you are handling multiple states you use a state machine (using enumerators) and you can have multiple of those if you want you just need to separate concerns like a state machine for combat and a state machine for movement. And yeah it can only be at one state at a time on each state machine but that helps a lot with organizing and keeping your code clean and understandable. What you are describing sounds like boolean/state hell to me.

But that’s just my opinion. If it works for you then go for it

“What you are describing sounds like boolean/state hell to me.”

Exactly! My boolean variables are piling up in my Char BP and something tells me this isn’t the right way to do things in UE4. I’ve never used AnimGraph/state machine, I guess that’s my next stop. Thanks :slight_smile:

I would recommend just keeping different booleans if they are for different thigs and not in an array, since it will be very annoying to read and write to the right boolean. Boolean arrays are deffinatly avaible, (I have used one). If you have multiple booleans wich corresponts with each other I would recommend to use an array. In example if 2 out of 3 boolean are true do something. A place to store them could be the character BP, however some may argue that gamemode is better. I have only used the characterBP and save games to store variables that have to do with the character.
Also if only one of the booleans can be true at the time I will suggest using enumerations since they make live a lot easier.

I agree with that last sentence. I’m still learning the engine so I have a long way to go. Thanks for the info.