Hi, my goal is to add functions to the Native Integer type with Bitmask meta option.
After trying some “things” based on my pure c++ knowledge like Inherite from Integer ( look impossible ) and making a templated UObject (impossible for sure) I decided to make this things that’s work :
Consider following code as sample with more Base function and more Enum to treat with
you still need to do your bitwise operations on the variable as expected
for C++ doesn’t require any inheritance it is a subset of UENUM
you can look here https://forums.unrealengine.com/t/bitmask-warning-spam/1194637
for a method that works to declare them, but I am getting a bunch of warning spam even though I looked through quite a few guides, and it works as it should just throws up numerous Warnings.
Was able to find a C++ method to use enums with more then 8 bits (so up to int32 maybe int64 but that would not be Net Replicatable)
detailed here:
Note: you can only have 1 non enum class per file; so if you only really need 1 of these relative to a UCLASS then you can declare it in the same header as the UCLASS, but if you need another you will need to have it declared and included from another file for each of them.
from your question I thought you were having trouble making bitmasks in general, but I will try for “how to make a function to work with general bitmasks” as I doubt you will only ever have 1 bitmask flag enum.
you might be over thinking it a bit. A bitmask is just how the integers are treated (we can manually set the bits to be effectively booleans) the data type is just an integral integer. The function just needs to take in 2 integers of the desired type (uint8, or int32) then spit out a bool.
in pure blueprints you could give this function to some reachable object (Game Instance, the player Character, or something else that is relatively static):
-created 2 Integers (both where set to bitmask)
-on the Game Mode gave a function that takes in 2 integers, and spits out a bool
then in the calling exec string need to Get Game mode then Cast to [BP_GameModeName]
in C++ you could make this a member function to a BlueprintFunctionLibrary (a static non-instance collection of functions)
// split up as desired
static bool HasAllOf(int32 inTarget, int32 inModel){
return (inTarget & inModel) == inModel;
}