Search Unity

[Bug #1229334] Self referenced prefabs sometimes reference the prefab Asset

Discussion in 'Prefabs' started by ARGB32, Mar 20, 2020.

  1. ARGB32

    ARGB32

    Joined:
    Feb 20, 2013
    Posts:
    15
    It looks like sometimes unity will link a field in a component on the prefab back to the Prefab asset in the project and not the instance in the scene.

    I can mess the with prefab directly in a text editor and get it to switch which of the components point to the asset and which points to the instance. For identical components.

    The upshot is there's no apparent reason why sometimes it might pick the asset over instance. It's not limited to nested prefabs, it happens when it's just the prefab in the scene.
    When playing the game it will bake it down to the instance correctly only 'sometimes' too but that looks to be a different issue.

    The only way to make sure it doesn't happen is to apply the setting as an override value and keep the override (don't apply to the underlying prefab). This is a pretty critical bug with prefabs in 2019. And again I want to stress this isn't limited to nested prefabs.


    Repro:
    Load scene
    Select MainCameraFP
    Select 'Main Camera' field in the first custom pass component to find the target - it will target the prefab instance
    Select 'Main Camera' field in the second custom pass component to find the target - it will target the prefab asset
     

    Attached Files:

  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Are you using the polymorphic serialization support introduced in 2019.3, also known as SerializeReference? There is a bug in that feature which matches what you describe. This seems to be fixed in 2019.3.7 (when that comes out).
     
  3. ARGB32

    ARGB32

    Joined:
    Feb 20, 2013
    Posts:
    15
    We didn't have any of our code use it. However, looking at the source code for the RP:

    Code (CSharp):
    1. /// <summary>
    2. /// List of custom passes to execute
    3. /// </summary>
    4. [SerializeReference]
    5. public List<CustomPass> customPasses = new List<CustomPass>();
     
  4. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Yeah that would do it. All right, I hope this will be fixed for you once you're able to update to 2019.3.7.
     
  5. ARGB32

    ARGB32

    Joined:
    Feb 20, 2013
    Posts:
    15
    Just an update:
    Fixed in Unity 2019.3.7f1
     
    runevision likes this.