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

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

5611300--580984--BrokenUnity.gif

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).

We didn’t have any of our code use it. However, looking at the source code for the RP:

/// <summary>
/// List of custom passes to execute
/// </summary>
[SerializeReference]
public List<CustomPass> customPasses = new List<CustomPass>();

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.

Just an update:
Fixed in Unity 2019.3.7f1

1 Like