When adding an entry to a TMap using UE's property editors, in most cases the new entry comes with a default-initialized key (if such key already exists, the insertion fails). The case of a UENUM defined in C++ is handled differently though, as each new entry comes automatically with the first unused enumerator, which is very welcome. Unfortunately, this special case also has a bug: if the user deletes an existing entry from the middle of the list and then attempts to insert a new one, the following happens:
A preliminary investigation showed that, in PropertyHandleImpl.cpp:5776, function HasKey() behaves as expected, which allows the code to discover the first unused enumerator correctly. However, right after that, the call "Implementation->AddChild()" reuses map indices that were freed by previous entry deletions, and the new default-initialized item ends up not being in the last position in the internal array storage. The code following that wrongly assumes that the new item is the last one, and updates that wrong item to have the new unique key. As a result, the newly-inserted default-initialized enum is left unchanged, and the last item in the map is wrongly replaced.
UENUM(BlueprintType)
enum class EMyEnum : uint8
{
Enumerator0,
Enumerator1,
Enumerator2,
Enumerator3,
Enumerator4,
};
UCLASS()
class AMyActor : public AActor
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TMap<EMyEnum, FString> MyMap;
};
There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-219729 in the post.
1 |
Component | UE - Editor - Workflow Systems |
---|---|
Affects Versions | 5.4.3 |
Target Fix | 5.4.3 |
Fix Commit | 35178509 |
---|
Created | Jul 19, 2024 |
---|---|
Resolved | Jul 30, 2024 |
Updated | Sep 4, 2024 |