Using uint32:1 to Create a Boolean

Actually my question is already asked, but answers didn’t made me content.

I don’t think people at epic doing things in different ways for fun. I don’t think seasoned veterans of c++ doing things from different ways for fun. There should be a reason as to why they used uint32:1 to create a boolean. Thinking that even they use a rule to add ‘b’ to boolean variable name prefixes, it probably has a very good reason.

I would love to know that reason, thanks in advance.

Please epic staff and community share your knowledges with me :slight_smile:

Errr…

I forgot to say, at most of UE4 example projects and source code of UE4. uint32:1 is used to create a boolean.

Forgot the most important part in my question.

Hello,

You are absolutely right - there is a logical reason behind this. uint 32 is used to create a Boolean because of bit fields and alignment. Basically, these are the tools that allow more effective memory management.
If you like to learn more about bit fields, please go here:

Hope this helped! Good luck!

I actually know about bitfield to some degree and that article helped some.

Just to confirm, if i use uint32:1 i will just have 1 bit while i use a bool i will have 32 or 64 bits and many bits wasted. This way we are saving memory, right?

Yes, you are right. You see, a bool should be at least one byte long (due to processor limitations). However, since there are 8 bits in a byte it has enough space to keep 8 bits (or 8 bools).
Thus, if you have a data structure featuring multiple bools, you don’t have to specify a byte for each - one byte can be shared.