MixedRealityToolkit-Unity icon indicating copy to clipboard operation
MixedRealityToolkit-Unity copied to clipboard

StateVisualizer prefab variants can corrupt prefabs

Open Zee2 opened this issue 3 years ago • 1 comments

Describe the bug

When making a prefab variant and changing/adding effects, you can get into an inconsistent state where the local copy of the repo + with your Library cache makes the correct behavior appear, but clearing the Library and/or checking out the same code into a new project results in corrupted prefabs.

To reproduce

Steps to reproduce the behavior:

  1. Make prefab variant of button
  2. Add/modify effects
  3. Save, commit changes
  4. Clear library
  5. Prefabs corrupted

Expected behavior

Prefabs should appear as they do with or without clearing the Library and should behave consistently across projects.

Zee2 avatar Oct 05 '22 00:10 Zee2

@JonathanPalmerGD

Zee2 avatar Oct 05 '22 00:10 Zee2

Katie H and I determined this is a Unity YAML serialization bug related to immutable packages wherein prefab variants that are variants of prefabs in immutable packages will have the incorrect YAML format serialized to disk.

Zee2 avatar Oct 20 '22 05:10 Zee2

Further investigations:

  • The 2021 serialization, when adding a new entry to a list and then immediately defining it (this example resizes from 1 -> 2, and defines the new object), does this:

    • Overrides size of list: propertyPath: ListOfReferences.Array.size value: 2
    • Defines new RefID inline: propertyPath: ListOfReferences.Array.data[1] value: LONGNUMBER
    • Immediately, for subsequent entries in the yaml, begins referring to this entry by the LONGNUMBER.
    • Specifies the type and assembly: propertyPath: managedReferences[LONGNUMBER] value: MyAssembly MyNamespace.MyType
    • Specifies the new value of this item: propertyPath: managedReferences[LONGNUMBER].SomeValue value: 42069
  • The 2020 serialization, which is observed in MRTK's override of Action Button on Empty Button, appears as follows

    • Overrides size of list: propertyPath: ListOfReferences.Array.size value: 2
    • Does not define a new refid.
    • Specifies assembly and type of the item: propertyPath: ListOfReferences.Array.data[1] value: MyAssembly MyNamespace.MyType
      • Notice: the property path is NOT a RefID, it's a path!
    • Specifies new value of the item: propertyPath: ListOfReferences.Array.data[1].SomeValue value: 42069
      • Like above, the property path is NOT a RefID, it's a path!

When the 2020 packages are consumed in 2021 project, Unity 2021 tries to make a 2021-formatted override on a 2020-formatted asset, which causes the problem. It tries to refer to the serialized item by managedReferences[LONGNUMBER] even though LONGNUMBER does not actually exist in the base asset.

Zee2 avatar Oct 26 '22 01:10 Zee2

@shaynie We'll might be removing support for 2020 with PR 11345. Can you investigate the impact here.

AMollis avatar Mar 02 '23 22:03 AMollis

https://github.com/microsoft/MixedRealityToolkit-Unity/pull/11465 Upgrades Unity to 2021.3 and re-serializes all prefabs.

shaynie avatar Apr 14 '23 17:04 shaynie