can someone tell me why the ShooterGame uses “unit32” types for a bool?
In the ShooterWeapon Class, there are bools with the normal bool type and with uint32.
Why would you use uint32 for a variable that should be true or false only? /:
Are they passed over the network or replicated in any fashion? That would explain it.
Bools are 32 bit (i think) when they get sent in packets, so an integer sends more information at the same size, handy if you want to flag multiple things with the same set of data.
Hm no, for example the ShooterWeapon.h. There are bool like this:
/** inifite ammo for reloads */
UPROPERTY(EditDefaultsOnly, Category=Ammo)
bool bInfiniteAmmo;
/** infinite ammo in clip, no reload required */
UPROPERTY(EditDefaultsOnly, Category=Ammo)
bool bInfiniteClip;
and there are uint32 like this:
/** is fire sound looped? */
UPROPERTY(EditDefaultsOnly, Category=Sound)
uint32 bLoopedFireSound : 1;
/** is fire animation looped? */
UPROPERTY(EditDefaultsOnly, Category=Animation)
uint32 bLoopedFireAnim : 1;
Both representing bools if i’m not wrong. But i don’t see why there are uint32 and not bools.
bLoopedFireAnim is set to true/false inside the cpp.
Also bInfiniteAmmo is set to true/false inside the cpp.
I suppose it could be because c++ recognizes integer representations of bools, I assume not just one person made the code for shooter game, or if they did it was possible they were just being experimental. (trying to break things?)
I honestly am just throwing conjecture now, but if you find a more telling reason it would be cool to know.
This is a bit field of a single bit (the : 1 means one bit, not initialize to true). So generally 32 of these variables in a given class/struct has the same memory footprint as 1 of these variables in a given class C Bit Fields | Microsoft Learn
As to why, I am not sure. On different platforms, could be a combination of byte alignment / performance / possible memory savings (bool being implemented as an int by the compiler) / personal preference, or even legacy UE4 reasons.