Search Issue Tracker
Fixed in 2018.3.X
Fixed in 2019.1.X
Votes
51
Found in
2018.3.0b1
2018.3.0f2
2019.1.0a1
2019.2.0a1
Issue ID
1116476
Regression
Yes
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
Comments (49)
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Crash on mono_dump_native_crash_info when changing a Particle System Renderer’s Material Shader to Standard Unlit
- VFX Prefab doesn’t have Preview icon in Project window and Preview window is empty in Inspector window
- Visual Effect Graph error message does not disappear and lasts forever until the Visual Effect Graph is reopened even when the error causing connection/node is deleted and Visual Effect Graph is saved
- “RenderSettings customReflection texture has invalid type” error keeps getting thrown even when Environment Reflections was set back to Skybox from Custom with an invalid texture
- Particle System with the custom Material breaks the Scene view when the material is using a Shader Graph with the Texture with the power of negative value
edwardrowe
Feb 06, 2019 14:02
This also causes an issue with Editing colliders in the Prefab sandbox. When in Edit mode on a collider's component, after you change a vertex on the collider if you have AutoSave enabled it will exit out of Edit mode.
ProTip - don't use AutoSave in the Prefab Editor.
bjarkeck
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.
if (AssetDatabase.Contains(instanceId))
{
// 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;
if (realWrapper)
{
// And gives you the new reference.
realInstance = realWrapper;
return true;
}
}
}
return false;
}
Demigiant
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 :|
tweedie
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!
SaltwaterAssemnly
Jan 30, 2019 09:59
Please fix asap!
trenthm
Jan 16, 2019 15:06
Same as @NONGBENZGAMES for me
trenthm
Jan 16, 2019 15:05
Same as @NONGBENZGAMES for me
nongbenzgames
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.