Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Prefab Variant Missing References and Losing Parent Settings

Discussion in 'Prefabs' started by kwhipke1, Jan 12, 2020.

  1. kwhipke1

    kwhipke1

    Joined:
    Jan 6, 2020
    Posts:
    2
    Sorry if I'm not doing this through the proper channels, I just wanted to make sure this is brought to the attention of Unity development team. There is an issue marked as "resolved" in the issue tracker but this (or a similar problem) is still affecting quite a few projects other than ours and is eating up a lot of our dev team productivity. I'm not sure if I should create a new bug report for it, people are still adding comments to the issue because it's the first google search result.

    Here's the issue in question: https://issuetracker.unity3d.com/issues/prefabs-references-are-lost-when-modifying-prefab

    Notice many recent comments complaining about prefab references.

    The issue we are personally having is that, after doing a standalone build (ctrl + shift + b), we see 2 things happening (sometimes only one of them happens):
    1. Scriptable Object assets which reference prefab variants now show as "Missing". We can usually fix this by committing unsaved changes then doing a git reset --hard.
    2. Prefab variant components seem to lose all of their settings. Neither their overridden settings or the settings inherited from the parent show up in editor. We can usually fix this by doing a Reimport on our prefab folder.

    In all cases, if we look at the actual YML of the meta / prefab / assets, it's the same as it is regardless of if we see this issue or not. But when we actually run the game in the editor after seeing this issue, it behaves as if that stuff is missing.

    This only seems to affect prefab variants and references to prefab variants.

    I might be able to work on an actual reproduction so I can submit it but it's going to take some time.

    Edit - oops, forgot to say I am on 2019.2.17f1
    EDIT2 - 2 things to clarify. 1) When we see this issue, the YML of the meta / prefab / assets is the same as when we don't see this issue. 2) Regardless of what we see in the editor, the issue doesn't show up in standalone builds of the game (ctrl + shift + b), it only appears in the editor and when we run the game in the editor.
     
    Last edited: Dec 15, 2020
  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
  3. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    I'm still running into this issue on 2019.3.4f1
    It keeps changing the file ID of a prefab variant nested within another prefab, then losing its reference.


    It's possibly related to usage of asset bundles, but both these prefabs belong to the same bundle. Besides that, project is sometimes losing texture references on materials.
    Pinning down this bug and creating a minimal repro is hard work. I'll attempt it, but can't promise anything.

    Update: I don't think there's a reliable repro at all. Modifying and saving prefabs and scenes, then rebuilding asset bundles for multiple platforms randomly cause this.
     
    Last edited: Mar 15, 2020
  4. TS-Trooper

    TS-Trooper

    Joined:
    Apr 30, 2019
    Posts:
    18
    I may have a similar issue

    I have a character and several derived characters. They have a different mesh and a different material.
    Now the name of the meshes in the model (that is part of the base-prefab) changed.

    Suddenly the overrides that are set in the prefab variants don't apply anymore.It seems like the variant lost the connection to the setting it was meant to override.

    How can this issue be tackled? I can't find how the override finds the object/component of which it overrides the values.
    I am guessing it finds it by some sort of GUID?
     
  5. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    Are you using Cinemachine ?
     
  6. TS-Trooper

    TS-Trooper

    Joined:
    Apr 30, 2019
    Posts:
    18
    We use cinemachine in the project, but these prefabs have no relation to it whatsoever.
     
  7. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    As soon as I removed Cinemachine from the project - the problem is occurring much less often (because i'm not resaving the prefab as much).
    I was using CinemachineVirtualCamera script in the prefab variant that was changing fileID for no reason (then all references to that prefab variant were broken).
    Besides, a prefab that held the reference to a broken prefab variant was present in a scene.
    CinemachineVirtualCamera was causing the scene to become dirty (without any changes) very often and asking to resave with an asterisk.

    This is very difficult to reproduce and doesn't happen every time, so I'm not even going to bother. Someone has to find a somewhat stable reproduction so Unity could fix this.
     
    Last edited: Apr 14, 2020
  8. ClockStone_Helmut

    ClockStone_Helmut

    Joined:
    Feb 23, 2015
    Posts:
    12
  9. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    Maybe it has something to do with the AssetBundles ?
     
  10. oriolmanya

    oriolmanya

    Joined:
    Jul 4, 2012
    Posts:
    50
    Hi, it happened the same to me and it scared the S*** out of me that maybe the most key feature on Unity (keep the state of the scene and its relations), seems so unstable.

    In my case, the Inspector Component AIBrain of Corgi Engine, had lost all the references to Actions & Decisions, without showing any change in the Assets of my git. With that I want to suggest that maybe it's not a Unity problem, maybe it is related to Corgi Engine in my project.

    By now, has been solved by:
    1. Moving and disabling randomly some elements on the Scene
    2. Save the Scene & the Project
    3. Closed Unity
    4. Doing as somebody suggested: git reset --hard (This is dangerous to do if you have done a lot of work without git commit...)
    5. Reopen Unity again

    Hope it does not keep happening.

    Good luck!
     
    kenthalazo likes this.
  11. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
    I don't use Corgi, at this point I'm sure that it's definitely a problem with Unity. Thanks for the workaround though.
     
  12. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    610
    Don't think this is because it is Corgi

    Happens to me too and I don't use corgi. It is a big pain

    2019.3
     
  13. jonagill_rr

    jonagill_rr

    Joined:
    Jun 21, 2017
    Posts:
    54
    We're seeing a similar issue on 2018.4.18f1, having just upgraded from 2018.3.5f1. We have a SciptableObject that contains a reference to a component on a prefab variant. That component seems to have changed its fileID several times, including reverting back to the original value. Each time the value changes, the reference becomes invalid and displays and null in the inspector.

    Not sure how to narrow this bug down, but it's very scary to think that vital prefab references might be silently breaking without registering any file changes.
     
    forcepusher likes this.
  14. DanTaylor

    DanTaylor

    Joined:
    Jul 6, 2013
    Posts:
    119
    I am getting this (or something very similar) as well.
    To make matters worse, reverting files in my source control doesn't seem to repair the broken links.
    This is a freakin' nightmare, and costs me days of bug hunting every week, as it seems to happen totally at random causing my entire game to break in several places.
    Did anybody find a fix for this?
     
  15. jonagill_rr

    jonagill_rr

    Joined:
    Jun 21, 2017
    Posts:
    54
    The reference breakages seems related to files upgrading the new serialization formats, so we force reserialized everything using AssetDatabase.ForceReserializeAssets() and it seems to have gone away for now.
     
    xVergilx and forcepusher like this.
  16. cp-

    cp-

    Joined:
    Mar 29, 2018
    Posts:
    78
    We've had two occurences of this problem in our latest project with 2019.3.7f1: Modifying a prefab variant changed the fileID but not the GUID. The other dev still had fileID A, i had fileID B: So whenever we tried to reference the prefab variant the other one had a missing reference.

    I'm posting here to state in both cases it happend with prefab variants with their names containing a dot character (e.g. "Button.Sub"). Maybe it helps.
     
  17. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    forcepusher likes this.
  18. forcepusher

    forcepusher

    Joined:
    Jun 25, 2012
    Posts:
    227
  19. YuriyPopov

    YuriyPopov

    Joined:
    Sep 5, 2017
    Posts:
    237
  20. unity_KONFA0LDbFIXOQ

    unity_KONFA0LDbFIXOQ

    Joined:
    May 2, 2020
    Posts:
    1
    Hello, I'm new in photon,

    I have a problem, but before I’ll explain a little bit what my game looks like : it's a 2d game where there is a single player mode where you can farm rarer weapons than others have armor, improve hit points, have passive or active artifacts ... A kind of solo "rpg"

    So this is my problem now, I have instigated a "pvp" system in 1v1, for the moment the room system works but the problem is that I would like our characters with all their characteristics to be instantiated with the opposing player, (he doesn’t there will be no movement, it's just a question of look) the problem is when we do a prefab in the resources folder we can not have all the mesh of the solo mode, the 2 players are identical with the basic skin and equivalent characteristics. So I would like to find a way to instantiate your own character without passing the prefabs in the resources folder!

    I inquired and saw things like" viewID" or "RPC" but it did not work for me, or simply I did it wrong maybe?

    Any help would be welcome !!!

    Thank you for your help,

    Cordially.
     
  21. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    This happened to me as well on Unity 2019.2.21f1.
    I've used prefab variants and locally everything builds just fine. But when the build is performed via Unity Cloud some of the prefab variant references went missing in the build, throwing null refs.

    This one has helped to me to "sync" state to the same one as on the Cloud (it seems like ForceReserializeAssets is done automatically on the Cloud), so I've wrote this small utility editor script (in case if happens again or anyone encounters this):
    Code (CSharp):
    1. using UnityEditor;
    2.  
    3. namespace EditorExtensions.MenuItems {
    4.    public static class ReserializeAssets {
    5.       [MenuItem("Tools/Force Re-Serialize Assets")]
    6.       public static void ForceReSerializeAssets() {
    7.          AssetDatabase.ForceReserializeAssets();
    8.       }
    9.    }
    10. }
    11.  
    Put it in any Editor folder, and use Tools/Force Re-Serialize Assets from the menu;
    Then fix missing references, save it, re-serialize again (just in case) and it should be fixed.

    Not sure what's causing this though.
     
    mehaeljenkin likes this.
  22. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,910
    Just had almost all my prefab variants reset for no reason. That's fun.

    2019.3.6f1

    Reimport mentioned in first post semi-fixed it. Minor parts are still wrong such as RectTransform top/button/etc positioning, including scene-specific overrided positions and also in-prefab.

    I submitted a bug report before reimporting. Also got a message about some root was deleted or not existing when trying to reimport. Then couldn't open any variant prefab. Had to restart editor.
     
    Last edited: Aug 28, 2020
  23. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    @Stardog

    You mention in the report alt-tabbing back to the editor.

    Were you editing scripts and maybe had some compile errors?
    Which IDE were you using?
    Did you have some plugin installed that connects the IDE to the Editor and will async compile the scripts in the editor while you are working in the IDE?

    Any information you might have that could help us track down why this happens would be much appreciated.
     
  24. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,910
    I was in prefab editing mode when I tabbed back in. I don't remember if it started to compile anything. I am using VS 2017 Community. I don't have plugins that compile scripts when tabbed out.
     
  25. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    @Stardog

    Ok, so just to make sure I understood correctly.

    You were editing a prefab in Prefab Mode
    You tabbed out of the editor to do some work
    You tabbed back into the editor which was still in prefab mode.

    What were you editing outside the Unity Editor?
     
  26. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,910
    I was probably only using Firefox. I didn't tab in from VS.
     
  27. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    @Stardog

    So you did not change anything in the project, just a tab out to do some research and then tab back in?
     
  28. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,910
    I believe so, because I was editing UI prefabs, not writing code. I think the prefab was unsaved if that matters.
     
  29. kenthalazo

    kenthalazo

    Joined:
    Mar 4, 2022
    Posts:
    4
    For some reason i just reloaded the configuration files and changed some random variables and well, after copying the meta prefab files it came back to normal.