Search Issue Tracker
Fixed in 2018.3.X
Fixed in 2019.1.X
Prefab's references are lost when modifying prefab
How to reproduce:
1. Open attached "PrefabReferenceLostRepro.zip" project
2. Go to Assets -> Scenes and open 'SampleScene'
3. Click on 'Spawner' and call 'Log' in the ContextMenu in the Inspector
4. Observe the Console
5. Go to Assets, open Enemy in Prefab Mode and edit it (e.g. change the position)
6. Repeat 3, 4 steps
Expected result: Console returns 'Enemy(Enemy)'
Actual result: Console returns 'null'
Reproducible: 2018.3.2f1, 2019.1.0a14, 2019.2.0a1
Not reproducible: 2017.3.0a1, 2017.4.18f1, 2018.3.0a11
Fixed in: 2018.3.6f1, 2019.1.0b4, 2019.2.0a6
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
- Input Field ignores first keyboard input when calling Focus() from code
- GC Alloc when using Graphics.RenderMeshInstanced
- [VFX Graph][URP] VFX crashes on URP when dragging VFX asset to the Hierarchy window
- InvalidOperationException when using AsyncGPUReadback.RequestIntoNativeArray
- Generated Entities look different when Depth Priming Mode is changed
Feb 03, 2019 20:40
Interesting workaround with the AssetModificationProcessor. Don't know if it's better or worse, but we found out that the AssetDatabase can still tell you things about the object even though it has become "fake null". So here is the solution we used in Odin for anyone interested:
private static bool ComponentReferenceIsBroken(T component, ref T realInstance)
var uObj = component;
var oObj = (object)uObj;
if (oObj != null && uObj == null) // Checks for fake null.
// It is safe to get the InstanceId, even though it's fake null.
var instanceId = uObj.GetInstanceID();
// The AssetDatabase still knows the broken object, and here it returns true if it's a reference to a prefab.
// If it returns false, then it could either be destroyed or just "fake null" as serialized unity objects often are.
// This parts gets the new reference from the prefab.
var path = AssetDatabase.GetAssetPath(instanceId);
var realWrapper = AssetDatabase.LoadAllAssetsAtPath(path).FirstOrDefault(n => n.GetInstanceID() == instanceId) as T;
// And gives you the new reference.
realInstance = realWrapper;
Feb 03, 2019 19:32
I investigated this a lot to find a workaround, and reached the conclusion that the new prefab system does a terrible thing: each time a prefab is saved it is now actually recreated, not updated. That means that, while serialized references are kept (GUID based), normal references are lost. It is really, really bad.
The best workaround I found is to use Unity's AssetModificationProcessor to store the path of the saved prefabs just before they are saved, then use an AssetPostprocessor to reload them from said path after they have been reimported. It's a delicate hell :|
Jan 31, 2019 23:49
Why is this not Priority 1? The tooltip for Priority 1 mentions "data loss" - this bug nulls out your references. It's entirely project breaking. It fundamentally breaks how Unity is meant to work.
2019.1 cannot ship with this, it's bad enough it made it to 18.3; it renders the new prefab workflow redundant for anything with a mono reference. Very sad, because nested prefabs are fantastic!
Jan 30, 2019 09:59
Please fix asap!
Jan 16, 2019 15:06
Same as @NONGBENZGAMES for me
Jan 16, 2019 15:05
Same as @NONGBENZGAMES for me
Jan 13, 2019 13:05
I too have references in other scripts going missing when updating prefabs. Components randomly get new FileIDs for some reason according to my Git. This has happened since the beginning of new prefab workflows to the latest 2019 alpha13. Not sure if it's due to a faulty upgrade process but this has been project breaking for months and needs attention.