How would you go about replicating TStaticBitArray or TBitArray variables? (std::bitset analog)
These types are not allowed by UPROPERTY() macro so i can’t just set them to replicate.
I could implement it by using int to store flags instead, but it would kill my programming ■■■■■.
My workaround is the code below. this way you have 32-64 bools in one int (depending if you package for x32 or x64)
UPROPERTY(VisibleAnywhere, Replicated)
int replicated_flags; // 0=isA, 1=isB, 2=isC, 3=isD
//Getters
inline bool getReplicatedFlagAt(int index){return !!(replicated_flags & pow(2,index));}
bool isA() {return getReplicatedFlagAt(0);}
bool isB() {return getReplicatedFlagAt(1);}
bool isC() {return getReplicatedFlagAt(2);}
bool isD() {return getReplicatedFlagAt(3);}
//Setters
inline void setReplicatedFlagAt(int index, bool new_val){replicated_flags = (new_val ? (replicated_flags | pow(2,index)) : (replicated_flags & ~pow(2,index)) );}
void setIsA(bool new_val) {setReplicatedFlagAt(0,new_val);}
void setIsB(bool new_val) {setReplicatedFlagAt(1,new_val);}
void setIsC(bool new_val) {setReplicatedFlagAt(2,new_val);}
void setIsD(bool new_val) {setReplicatedFlagAt(3,new_val);}