Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Failed to unpersist: Bug

Discussion in 'Prefabs' started by punk, Jan 28, 2019.

  1. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    407
    I've been having this bug popup for years sometimes it get fixed and goes away for a while, but it's back. Seems to be related to prefabs (Using 2018.3.3f1)

    I don't know what causes it, but there is two things that happen - either

    1. When you press play you get a bunch of error message such as

    Failed to unpersist: GameObject ID: -987586 FileID: 1723775924
    Failed to unpersist: MonoBehaviour ID: -987584 FileID: 1851524827
    Failed to unpersist: MonoBehaviour ID: -987582 FileID: 1851524828

    your scene prefabs get destroyed and you have to press stop unload and reload your scene

    2. When to press stop you get the bunch of error messages as above and then it deletes everything in your scene, you then have to unload and reload your scene

    Either way you're scene gets trashed, seems like its been around since multi scene editing

    Could somebody from Unity give some insight on what this 'Failed to unpersist' actually means, like under what conditions is it thrown? that way I can attempt to get to the bottom of it and submit a repo

    if anybody else has any insight that would be helpful thanks
     
    Last edited: Jan 28, 2019
  2. diviocy

    diviocy

    Joined:
    Apr 8, 2017
    Posts:
    4
    I had this occur with one of my scenes recently. Each time I made a change and entered play mode, the entire scene would get nuked with a ton of failed to unpersist errors. I could avoid this by saving my change, unloading and reloading the scene, but that's no way to work.

    What ended up working for me was closing Unity, deleting the Library folder in the project directory, and letting Unity regenerate it all on next load. This will take some time, but it's worth a shot. I'm on 2018.1.7f1.
     
    punk likes this.
  3. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    407
    Thanks for the suggestion, i've read that works for some people. It literally takes days upon days to rebuild my library these days cos its so big, so i'm rarely keen to do it, i did try it a few years back, but no luckl

    Currently i've found a work around by adding a delay of .1f seconds to start of the game cycle. If I remove the delay it starts happening again, it seems reated to prefab references in multiple scenes when calling Instantiate. Anyways it fixed it.

    But now I'm curious why it even happens at all.
     
  4. diviocy

    diviocy

    Joined:
    Apr 8, 2017
    Posts:
    4
    Alright, I've gotten to the point where deleting my library doesn't help, so I must ask about your fix. When you say delay the game cycle, do you mean setting timeScale to 0 at first then setting to 1 at a particular point in time, or something else?

    I'd greatly appreciate the help!
     
    pedroharres likes this.
  5. pedroharres

    pedroharres

    Joined:
    Sep 14, 2018
    Posts:
    5
    me too! :)
     
  6. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    414
    I believe the delay works because as some other stated, corruption occurs when Instantiating (within?) a prefab at awake scene time :
    https://discussions.unity.com/t/fai...r-id-and-then-unity-destroys-our-scene/203205

     
  7. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    407
    I know this is old, it still happens to me and the delay did not fix it, what I did in the end was put the prefab pool in a separate scene which gets loaded at runtime and then used the domain reload option for instant play mode, that way the scene just gets trashed on exit and it is no longer a problem, hope it helps.
     
  8. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    414
    Good to know it solves your issue. I've tried several things but I still can't pin point what causes the corruption. I have 3-4 concurrent scenes and some dontDestroyOnLoad as well + prefab instancing ...
    What I observe is that some of the root objects of one of the scene are moved and / or duplicated on an other one either at play start or exit.

    This is what happens, (yellow are all duplicated unwanted stuff), side note, see how the D_GameUI prefab gets duplicated yet whithout the blue font indicating its a prefab.

    I just can't track this down, the bug is here for at least a year ...

    upload_2023-11-9_17-15-48.png
     

    Attached Files:

  9. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    407
    Hmmm yeah not sure, I don't use don't destroy on load I just have separate scenes and manage it myself, so I don't think its related to that,

    now I've had a few years to think about this issue :D I wonder if it has something to do with missing scripts, do any of your prefabs have missing scripts? my project is massive and I'm betting I have some, the other thing it could be related to is I never had this issue back in the old days before unity had additive scenes, it could be caused when scenes are dramatically altered at runtime and then unity struggles to reset them properly when exiting play mode. This is what led me to creating my prefabs inside a junk scene that I didn't care about, ie just a blank scene that I use for runtime generation.
     
  10. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    414
    This seems like a good piece of advice. Not really looking forward the refactoring .. but hell, atm I need to relaunch the editor each time I exit play mode ... Luckily I'm using FSR and can do a lot of iteration in real-time.

    The Game_UI prefab is quite large, as it includes all the game ui. I'll try unpack it and see.
    [Edit: Not related]
     
    Last edited: Nov 10, 2023
  11. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    414
    Ok so,
    I applied a recipe I read on another thread (don't remember which), I created a new scene moved all content of my previous "BoardGenericManager" scene to it and updated the ref to the scenes. So far, so good, I managed to play/exit without problems (HUGE UPGRADE)
     
    Last edited: Nov 10, 2023
    punk likes this.
  12. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    407
    Glad it worked out ;)
     
    Whatever560 likes this.