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

Scene Management

-

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)

  1. Mehrdad995

    Feb 06, 2019 15:11

    This really sucks, it has broken my project which I'm working on for almost 18months
    switched to 2018.2.3f1 and had enough bugs to made me switch to 2019.1.0a14 and I wish I stayed on 2017 version.
    now my gigantic prefab has lost almost all of its mesh components reference and I have to re-assign over 200 meshes, come on :/

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

  3. 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;
    }

  4. 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 :|

  5. 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!

  6. SaltwaterAssemnly

    Jan 30, 2019 09:59

    Please fix asap!

  7. trenthm

    Jan 16, 2019 15:06

    Same as @NONGBENZGAMES for me

  8. trenthm

    Jan 16, 2019 15:05

    Same as @NONGBENZGAMES for me

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

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.