Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.


Product Version: UE 4.10
more ▼

asked Oct 20 '16 at 02:51 AM in Blueprint Scripting

avatar image

31 6 8 12

avatar image MacDx Oct 20 '16 at 03:15 AM

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?

avatar image c0ldpr0xy Oct 20 '16 at 06:57 AM

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?

avatar image learningOver Oct 20 '16 at 10:13 AM

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.

avatar image c0ldpr0xy Oct 20 '16 at 10:17 AM

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.

avatar image learningOver Oct 20 '16 at 10:32 AM

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 :P

avatar image c0ldpr0xy Oct 20 '16 at 09:48 PM

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

avatar image MacDx Oct 20 '16 at 11:16 PM

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?

avatar image c0ldpr0xy Oct 21 '16 at 12:24 AM

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...

avatar image MacDx Oct 21 '16 at 01:05 AM

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

avatar image c0ldpr0xy Oct 21 '16 at 05:10 AM

"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 :)

avatar image vb4 Oct 20 '16 at 10:31 AM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Oct 21 '16 at 01:14 PM

avatar image

413 17 15 31

avatar image c0ldpr0xy Oct 22 '16 at 07:04 AM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question