Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Unity prefab variants messed up after refactoring field's names

Discussion in 'Editor & General Support' started by FVS, Sep 13, 2023.

  1. FVS

    FVS

    Joined:
    Aug 10, 2015
    Posts:
    56


    I detailed the steps to produce the bug in the description of the video, I copy them here, too:
    1. Create a new script: (0:00)
    2. Create a field named fieldA: (0:29)
    3. Create a prefab and set value for fieldA: (0:53)
    4. Create a variant of the prefab: (1:14)
    5. Change the value of fieldA in the variant: (1:21)
    6. Notice Unity does recognize the change: (1:27)
    7. Add FormerlySerializedAs: (1:33)
    8. Rename fieldA to fieldB: (1:45)
    9. Now Unity doesn't recognize the change: (2:04)

    I've filed a bug report, but they said they couldn't reproduce it and disqualify the bug. But you can try this in every Unity version from 2021.3 LTS to the latest release (2023.3.7). I replied to their email with an attached package on Sep. 4, but they haven't replied yet.

    Please, someone confirms it happens to you, too.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    I don't see where the problem is supposed to be seen in your video.

    You do change the fieldB value of the variant's script but then you manually revert it.

    The mouse bouncing back and forth between the two windows makes me think that maybe you expect the variant value change to appear in the original prefab's script as well. But that is not even the case for "fieldA", and expected because changes to a variant don't automatically propagate to the parent prefab.
     
  3. FVS

    FVS

    Joined:
    Aug 10, 2015
    Posts:
    56
    First of all, you can try to reproduce it yourself and see the problem.
    Second, whatever the process, from 2:30, we reached the state where the variant has a different value (15) from the original (10), but Unity doesn't recognize that (the field in the inspector doesn't highlight, there's no revert menu when right click), so I can never revert the value. Now if I change the value in the variant, Unity recognizes the field has different value than the original, but when I revert, it doesn't go back to the original value (10).
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    Ah, I see, that explains it better. ;)
     
  5. FVS

    FVS

    Joined:
    Aug 10, 2015
    Posts:
    56
    And that's not just an experimental find, but a real issue I had when I was developing a commercial project, it took me quite some time to spot the issue and I didn't find an easy fix as I had so many variants.

    Hope Unity will fix it soon :(
     
  6. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,899
    Indeed, I can reproduce this in 2022.3.9f1.
    After renaming the field with FormerlySerializedAs the connection to the original prefab's value seems to have been lost.
    It also behaves the same even if you enter prefab edit mode.

    It starts working again once you remove [FormerlySerializedAs]. I'm betting that this confuses the prefab variant lookup strategy in some way.
     
    FVS likes this.
  7. FVS

    FVS

    Joined:
    Aug 10, 2015
    Posts:
    56
    yeah, actually I had some idea that it was because how they handle the attribution FormerlySerializedAs, and how they handle field changes in the variant, I had to edit the meta files, and the process wasn't comfortable. I'm afraid in the future when I refactor my code and this happen again without me noticing it. (or maybe it already happened again but I just didn't know yet )