Hello everyone,
I’m stuck on a pretty weird thing and in fact I think I’m missing something.
I Made an enum class as a bitflags enum like this :
/**
* test Bitflags
*/
UENUM(BlueprintType, meta=(Bitflags, UseEnumValuesAsMaskValuesInEditor=true))
enum class EThingFilter : uint8
{
None = 0b000000 UMETA(DisplayName="None"),
IgnoreNullId = 0b000001 UMETA(DisplayName="IgnoreNullId"),
OnlyNullId = 0b000010 UMETA(DisplayName="OnlyNullId"),
EvenId = 0b000100 UMETA(DisplayName="EvenId"),
OddId = 0b001000 UMETA(DisplayName="OddId"),
OnlyAlphaName = 0b010000 UMETA(DisplayName="OnlyAlphaName"),
OnlyNumericName = 0b100000 UMETA(DisplayName="OnlyNumericName")
};
ENUM_CLASS_FLAGS(EThingFilter);
And then in a test UObject, I’m trying to implement a UFUNCTION like this :
UCLASS(BlueprintType, Blueprintable)
class TESTDIVERS_API UThingArrayStorage : public UObject
{
GENERATED_BODY()
public:
UPROPERTY()
TArray<UThing*> Things;
UPROPERTY(BlueprintGetter=GetInstanceName, BlueprintSetter=SetInstanceName)
FString Name;
UFUNCTION(BlueprintCallable, Category="Test")
TArray<UThing*> FilterThings(UPARAM(meta = (Bitmask, BitmaskEnum = "EThingFilter")) int32 Filter );
};
I want to be able to pass something like EThingFilter::OddId & EThingFilter::OnlyAlphaName to this parameter. And when I do this, the code won’t compile.
Is it possible ? Or Am I in the wrong direction ?
Thanks.
PS: Note that if I pass an integer it compiles.
dZh0
(dZh0)
June 18, 2025, 9:38pm
2
You’ve not shown the actual code that doesn’t compile and the actual error that is thrown as a starting point but I will go ahead and assume that you are not using the correct operator when passing the flags.
The proper operator in this case is bitwise or (|) not bitwise and (&);
Try FilterThings( EThingFilter::OddId | EThingFilter::OnlyAlphaName );
and tell how it went.
Thanks for your answer,
In fact I’ve posted the entire code, and I get an error when I try to put default values to the ufunction definition
tUCLASS(BlueprintType, Blueprintable)
class TESTDIVERS_API UThingArrayStorage : public UObject
{
GENERATED_BODY()
public:
UPROPERTY()
TArray<UThing*> Things;
UPROPERTY(BlueprintGetter=GetInstanceName, BlueprintSetter=SetInstanceName)
FString Name;
UFUNCTION(BlueprintCallable, Category="Test")
TArray<UThing*> FilterThings(UPARAM(meta = (Bitmask, BitmaskEnum = "EThingFilter")) int32 Filter = EThingFilter::OddId | EThingFilter::OnlyAlphaName );
};
And in fact I wanted to use, but maybe I’m wrong, FilterThing with Id that are Odd and Name with only alphaNum. That’s why I used & bitwise (&). It’s only a silly test to try to understant Bitflags.
But The real problem is that When I try the code above The compiler complains.
But again thank you for your answer.
dZh0
(dZh0)
June 18, 2025, 10:29pm
4
Hm… Is it possible it doesn’t want to make the implicit int conversion?
Also can you remove the UPARAM stuff in cast that’s doing something strange.
TArray<UThing*> FilterThings(uint8 Filter = EThingFilter::OddId | EThingFilter::OnlyAlphaName );
Does this produce the same error or not? Also what’s the text of the error exactly?
I think you pointed out.
To answer your question the error I get was :
Cannot initialize parameter 'Filter' of type int32 with EThingFilter
And When I try Your code I’ve got :
Cannot initialize parameter 'Filter' of type uint8 with EThingFilter
So You’ve pointed out the thing.
it doesn’t want to make the implicit int conversion
And now if I do :
uint8 Filter = StaticCast<uint8>(EThingFilter::OddId | EThingFilter::OnlyAlphaName)
UHT complains that :
C++ Default parameter not parsed: Filter 'StaticCast<uint8>(EThingFilter::OddId | EThingFilter::OnlyAlphaName)' [UnrealHeaderTool Error
So I tried to StaticCast to uint8 with :
UFUNCTION(BlueprintCallable, Category="DTFluxTest")
TArray<UDTFluxThing*> FilterThings(UPARAM(meta = (Bitmask, BitmaskEnum = "EThingFilter")) int32 Filter = StaticCast<uint8>(EThingFilter::OddId | EThingFilter::OnlyAlphaName));
Resulting in the same error.
And then I removed the exposition to blueprint like so :
UFUNCTION()
TArray<UDTFluxThing*> FilterThings(UPARAM(meta = (Bitmask, BitmaskEnum = "EThingFilter")) int32 Filter = StaticCast<uint8>(EThingFilter::OddId | EThingFilter::OnlyAlphaName));
And then it compiles. But can’t test it has it’s not exposed in BP… But Maybe it can help understand.