Search Unity

Bug Unpacking Prefab-Variant + [FormerlySerializedAs()] can result in permanently screwed up reference

Discussion in 'Editor & General Support' started by Jamez0r, Mar 11, 2021.

  1. Jamez0r

    Jamez0r

    Joined:
    Jul 29, 2019
    Posts:
    205
    I had a prefab variant that I no longer needed to be a variant, so I unpacked it (back to just the original prefab with its local modifications, just no longer a "variant").

    One of my fields has a [FormerlySerializedAs()] attribute on a variable. The thing that was 'dragged into that slot' in the inspector was on a GameObject that was added as part of the *variant* (aka it wasn't part of the base-prefab).

    When I unpacked the variant back to the base prefab, and clicked on the 'slot' in the inspector for that field, it selected the folder in the PROJECT view that the prefab-variant was located in (it should have selected the actual gameobject in my hierarchy).

    When I tried to just replace the reference by dragging in the real gameobject (that exists in the hierarchy) into that slot, it looked like it got set correctly (clicking on the slot showed that it was referencing the "real" one in the hierarchy), but after I ran the game it reverted back to the referencing the one in prefab-variant in the PROJECT view. Super strange.

    I also tried "Revert..." on the field, which also was reverting it back to the prefab-variant in the Project window. There was no way for me to override it, or reset it, or anything.

    I opened up the my script that has the reference with this issue, and noticed that the field had the [FormerlySerializedAs()] attribute. I removed that attribute and it fixed it.

    My guess is that I had assigned the reference with the "old variable name" in the prefab-variant, then changed the name of the variable and added the [FormerlySerializedAs()] attribute. And then after I unpacked the variant, it still used that formerly-serialized-as reference to maintain the reference to the prefab-variant in the Project window.

    I know I should submit a bug report but I'm really busy with my project right now. Maybe I can submit it this weekend - but does anyone know if this is a "known issue", or is it an actual bug? It could cause people some MAJOR issues - I'm lucky that I was able to figure out what was causing it, because I could do nothing to replace this reference issue from within the Editor. I also have no idea how many other [FormerlySerializedAs] references I might have on that prefab-variant that I unpacked? It's not going to be fun...

    Edit: I forgot to mention that I also tried completely deleting the Prefab Variant in the Project window - doing that resulted in the field slot showing "Missing". The issue was not solved until I removed the [FormerlySerializedAs] tag

    Edit 2: Unity 2020.2.0f1
     
  2. jeango

    jeango

    Joined:
    Dec 19, 2012
    Posts:
    109
    @Jamez0r Hey there, have you found a solution to this? I'm having the same kind of problem with non-variant prefabs. Did you open a ticket?