Download

TEnumAsByte Weird Value

Hi,

I have an enum defined like this:

UENUM(BlueprintType)
namespace EMyEnum
{
enum Type
{
Option0 = 0,
Option1
};
}

And the enum is used as a property in another class:

UPROPERTY(EditAnywhere, Category = “Blah”)
TEnumAsByte<EMyEnum::Type> Option;

The Option is set to Option0 (0) in the constructor and it is set to Option1 in the editor. At some point the value becomes “2”.

Any ideas?

Thanks.

In Visual Studio, set a Data Breakpoint on the enum property in the constructor. You should hit the break point when it changes to 1 in the editor, then continue and you should hit a breakpoint again when it changes to 2 and you can look at the call stack to see where that change is coming from.

Thank you for your help. This value is initialized as Option0 in the constructor and only changed in editor. When I set a breakpoint in PostPropertyChanged it is changed to 2, which is not a valid value. This actor has gone major changes on C++ side. Do you think it is a serialization problem. Maybe I should rebuild the actor?

I’ve had that happen before when I made some major changes to the class (and the serialized enum in particular). Just resave the actor (or toggle something and rebuild the blueprint) and it should fix itself.

I created a new instance of the object and the value came correct now. I think it is a serialization problem. Thanks for the posts.

TEnumAsByte is outdated, you should be using proper enum classes now