When copy/pasting property bags in the editor, IDs of FPropertyBagPropertyDesc can be duplicated, causing there to be reused IDs. Then merging bags in any way in code creates issues where two different properties have the same ID and therefore values cannot be correctly copied.
Steps to Reproduce
It looks like the property bag (or property bags) can contain duplicate IDs with different names, value types, etc. because no copy constructor is defined that prevents copying of the ID. Inserting the following code near the bottom of UPropertyBag::GetOrCreateFromDescs (I put it just above the [Content removed] it seems like IDs are intended to be unique.
We’ve are trying to add a copy constructor and copy assignment operator that set the ID to 0, but that will not fix up existing incorrectly serialized bags. I’m also not confident it is the right attempted fix.
for (int32 DescIndex = NewBag->PropertyDescs.Num() - 1; DescIndex >= 0; DescIndex--) { for (int32 iDesc = NewBag->PropertyDescs.Num() - 1; iDesc > DescIndex; iDesc--) { if (NewBag->PropertyDescs[DescIndex].ID == NewBag->PropertyDescs[iDesc].ID) { UE_LOG(LogCore, Error, TEXT("Duplicate id for %s and %s!"), *NewBag->PropertyDescs[DescIndex].Name.ToString(), *NewBag->PropertyDescs[iDesc].Name.ToString()); } } }
Hi Shovaen,
I attempted to reproduce this, but cannot. I must be doing it wrong. These were my steps:
- Create a new C++ project.
- Add a new class derived from AActor (BagTest).
- Add two FInstancedPropertyBag variables exposed as UPROPERTY(EditDefaultsOnly, Category = Test) (Bag1 and Bag2)
- Create a new Blueprint class inherited from BagTest.
- Add a property to Bag1.
- Note that UPropertyBag::GetOrCreateFromDescs() is called the moment I add a property here.
- Right-click Bag1 and Copy.
- Right-click on Bag2 and Paste.
- Note that Bag1 and Bag2 now have identical properties, but UPropertyBag::GetOrCreateFromDescs() is NOT called here.
- Click Compile and note that UPropertyBag::GetOrCreateFromDescs() is once again called, but there is no sign of an ID collision.
I inserted the debugging code snipped that you helpfully provided, and with a breakpoint set on the UE_LOG line, nothing ever got hit. Could you provide any more details about how your code is structured, or anything else you might have done that would recreate this issue?
Thanks Graeme, we’ve worked around this for now, but I do still want to figure out what is going on in case there is an engine level issue. Our release is in a few days so it might take me some time to get back to this. Would you like me to test it on a fresh 5.6 source install?
Hi Shovaen,
Any additional steps or tests you can do to create a reproducible case would be great. Unfortunately, if there’s not some reasonable reproduction steps, nobody can hunt for the bug. I noted the steps I took to try to reproduce it, but unfortunately, everything worked fine for me.