Search Unity

Prefab variants introduce lots of new loading bars and lag

Discussion in 'Prefabs' started by khalvr, Feb 26, 2019.

  1. khalvr

    khalvr

    Joined:
    Sep 12, 2017
    Posts:
    53
    I have a pretty large prefab in my scene, it has maybe 100 children all in all. I decided to make a prefab variant of it where i change the color of a handful of renderers. Now, every time i exit play mode, i get about 10-15 seconds of loading bars appearing regarding this prefab variant. It may not sound like much, but it gets annoying if you tend to jump in and out of play mode a lot. What's worse though, is that every time i edit anything in the original prefab (in the prefab editor), the editor locks up and shows a loading circle for a split second, presumably to instantly refresh the variant. I can't tell if it's actually related though, since the editor has always been rather unresponsive, most annoyingly it tends to randomly zoom or snap your view to certain positions as you move the camera around. Combined, these things will completely throw off all sense of precision while working.

    I have an Intel i7 processor with a GeForce 1080ti GPU, as well as an SSD drive, so i really don't expect the editor to be this sluggish.
     
    jrumps likes this.
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    Be sure to turn of "auto save" in the prefab view. That was a bad idea. Even a frame of delay after adjusting a field is a major discomfort.
     
    andreiagmu and jrumps like this.
  3. khalvr

    khalvr

    Joined:
    Sep 12, 2017
    Posts:
    53
    It's not just that... literally every time i save ANY asset, such as a scene, or create a material, i get the "Hold On" prompt appearing, mentioning the name of my prefab variant, even when it's not part of the scene i'm working on. It's ridiculous.

    As for the "auto save" option - i would prefer it if unity auto-saved whenever i left the prefab editor instead, right now i think it prompts you to save whenever you exit if it's not turned off.
     
    soleron and jrumps like this.
  4. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,278
    Yeah I'm not sure why, but complex prefabs results in quite a long time for saving... my UI prefab takes around 5-10 seconds, which is sort of silly.

    Also, prefabs that are placed a "lot" in the scene (even with just 10 instances) also results in lag, usually 5-10 seconds.

    Not sure why this does this :/
     
    soleron and khalvr like this.
  5. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Unity needs to do work for every Prefab instance in the scene when the Prefab is saved in order to merge changes to the Prefab into the scene instances. Unity also needs to reimport all Prefabs that depend on the saved Prefab due to being Variants of it or containing it nested inside. Each of those also need to be merged for each instance in the scene of those.

    Unless your Prefab is absolutely huge in terms of number of GamObjects and components, 5-10 seconds sound excessive if you have only 10 instances in total, and don't have other Prefabs depending on it that are themselves huge or appear many more times in the scene. If that's the case, feel free to file a bug report so we can look into why it's so slow.

    Also, note that there has been various performance improvements in later versions of 2018.3, so if you're not using the latest, try to do that and see if it helps.
     
  6. khalvr

    khalvr

    Joined:
    Sep 12, 2017
    Posts:
    53
    I am using 2018.3.5, and i only have a single instance in my scene - yet i have at least 10 seconds of loading screens popping in and out, even if the prefab variant is not even in the scene i have open.

    All this would be well and good if the system actually worked. I just found that after building the project, the prefab variant AND the original got completely F***ed up and some of their nested prefabs moved to random locations. Some of the changes i made to my variant were also lost, overall maybe 2 days of work. Screw this.

    I can't share my scene (in part because the project is large, and also i am not allowed to share it), and i'm not sure how to reproduce it without it. Should i submit a bug report anyway?
     
  7. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    If you're not sure how to reproduce it without it, then we likely won't be able to either I'm afraid. We'd love to look into this issue but the reality is just that we need repros in order to be able to...
     
    joshcamas likes this.
  8. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Sounds weird! We'd love to have a look if you can submit repro project and repro steps.
     
  9. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    418
    Sounds like you're modifying the prefab asset in your project folder during play mode. :eek: You should never modify a prefab asset during play mode because it will permanently alter (aka f*** up) that prefab asset and therefore all instances and variants based on it! You will also get issues when you build the project since prefabs can't be modified in builds. So make sure you're only modifying prefab instances loaded at run-time and not the prefab assets themselves in your project folder!!

    Placement in the scene doesn't matter because you're updating the prefab assets in the project folder. I'm also beginning to think that maybe prefab variants aren't what you actually need... Maybe you only need to override the prefab instances in your scene. This works exactly the same as variants. Only difference is variants can be reused between scenes.

    I think this is a great idea. Updating all prefabs whenever you make a tiny change to one of them can be really annoying, but having to confirm you want to save changes on close can be equally annoying. So I think adding a new toggle next to Auto Save called "Save On Close" that auto saves only when you close the prefab editor would be a really nice quality of life enhancement.
     
    Last edited: Mar 2, 2019
    andreiagmu likes this.
  10. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    We don't use the forum for tracking bugs and your steps of "Make a large prefab with about a dozen top level, nested prefabs." is a bit ambiguous to say the least. We need exact steps, or a project that contains the described objects. Please post the case number here when you've submitted a bug report with repro project and repro steps.
    https://unity3d.com/unity/qa/bug-reporting
     
  11. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    What use is that if it gets us no closer to being able to fix the issue?

    To be clear, keeping on talking about bugs in the forum but not submitting bug reports, even when we've made it clear we'll need it to be able to investigate, only wastes time and doesn't bring us closer to a solution.
     
  12. khalvr

    khalvr

    Joined:
    Sep 12, 2017
    Posts:
    53
    I am not. There is no reference to this particular prefab anywhere in any of my scripts. It also doesn't explain why i get this save dialog whenever i, say, create a new material - that just doesn't make any sense at all and is incredibly annoying. Besides, this issue is much larger than that - for instance, prefabs which are placed in the scene root will sometimes tend to get their transforms reset as well. Just recently i had multiple instance of the same prefab have their transforms reset, so that they are all in the same spot (these were not variants, but regular prefabs).

    Some components need to be respawned with their initial state, so i need prefabs for that. I just lost a bunch of work again though, so i kinda wonder if it isn't just worth it to keep two separate prefabs and maintain them separately, or to solve it using nested prefabs.

    Sometimes, discussing the nature of the bug is necessary in order to get enough information to post a bug report (since I've noticed that without exact reproduction steps, bug reports tend to be ignored). Many of us use Unity for a living, and we are not paid to reproduce bugs for you.
     
    jrumps likes this.
  13. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    My comment was a reply to jrumps (as indicated with the quote) since he posted specifically in reply to my request for a bug report, and commented that "it's pretty simple to make it happen.". Well, it's not simple for us, that's why we're asking for bug reports. If it's already simple for someone to reproduce but still they won't submit a bug report but rather just keeping posting about it, then it just doesn't seem like a productive approach, but it's their choice of course. It just won't get anything fixed.
     
  14. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,278
    Woah woah don't bring me into this
     
  15. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    @runevision I've submitted a bug report with a project where this is 100% reproducible if you guys are still looking for examples of the issue: Case 1134356
     
  16. khalvr

    khalvr

    Joined:
    Sep 12, 2017
    Posts:
    53
    Thanks a lot jschieck! That's great!

    On another note, i managed to find out some more about the issue with nested prefabs inside my variant losing their transforms. It seems to happen when i build, and it seems like lots of different prefabs get touched, even though i didn't change them. Here is a git diff on one file:

    GitDiff_1.jpg

    And here is another:

    GitDiff_2.jpg

    What i happening for me is that (at least) 6 different objects are getting rotated and moved. Instances of the same prefab gets moved to the same spot - basically, the transforms will match whatever values the root transform stored in their prefab has.

    By the way, is it legal to append new transforms to a prefab variant? I noticed that Unity complains if you try to change the order of them (which makes sense), but it is possible to add stuff to the bottom of the hierarchy. I'm wondering whether this is what is screwing things up, because after the first few times Unity screwed up the prefab, the two new objects have moved up the hierarchy (i have one prefab and one variant of that prefab both nested). Also, how about nesting a variant of one prefab inside a variant of another prefab?
     
    Last edited: Mar 7, 2019
    jrumps likes this.
  17. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Thanks, appreciated!
     
  18. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    418
    That is bizarre. Where are you creating these assets and does it happen when creating anything or only certain types?

    Can you elaborate on this? What do you mean by "Some components need to be respawned"? Are you completely sure you are not modifying components on the prefab itself?

    This could be related to the previous quote if you are resetting transform components somewhere else.
     
    Last edited: Mar 10, 2019
  19. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,129
    @jrumps, what's your Unity version? U can try latest 2018.3.8f1 at the time of writing and see your issue has been fixed or not. Looks like almost every week there is prefab bug fix.
     
  20. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    418
    Recompiling a script is a terribly slow way of tuning values and should be avoided. You should instead be editing an exposed value in the inspector. Using a ScriptableObject will also save changes made during play mode.
     
    Last edited: Mar 12, 2019
  21. khalvr

    khalvr

    Joined:
    Sep 12, 2017
    Posts:
    53
    I'm not sure if you noticed, but jschieck wrote that he had posted a bug report where this is 100% reproducible.

    It happens seemingly regardless of what asset type i create. It also happens whenever the scene is saved.

    Each component has a string tag referencing their prefabs. When the object is to be respawned, a respawn manager object has a dictionary of tags and prefabs and uses this to load and instantiate a copy of the object. Regardless, the loading screens appear regardless of whether objects have been respawned, and there is only one point in the code where this instantiation occurs. I can assure you that i'm not modifying the underlying prefab or its components.

    I already posted a git diff of how the fileID's are changed. Every change in that diff happened after i built the player, without doing anything else inbetween (i have a habit of always pushing my project before i build, for this very reason). Also, let me point out that this never happened before i upgraded to 2018.3.

    Well, the whole point of this thread was to gather other people's experience on this bug so that a common factor could be discerned. From my experience, there is lots of proof (apart from the above mentioned bug report) binding the loading bar issue to prefab variants.

    EDIT: Now that i look at it, there is a fix in 2018.3.8 which seems to address the latter issue:

    I will try upgrading and see if the problem persists.
     
    Last edited: Mar 11, 2019
  22. IsaiahKelly

    IsaiahKelly

    Joined:
    Nov 11, 2012
    Posts:
    418
    You don't understand the purpose of bug reports; they have nothing to do with "general efforts to improve a system". Unity is always working on that. But as you've pointed out already, Unity has millions of users, so it's quite impossible for them to catch every possible issue.

    Bug reports are meant to help pinpoint exact issues they have missed so they can fix them. Without such bug reports it can be very hard if not impossible to to find the problem. This doesn't mean they won't try to fix it without a bug report, but it doesn't make their job any easier either.

    You also speak as if you're issue is universal but I have never experienced it myself, even after trying to reproduce it. Does that mean it doesn't exist? Of course not. But it may not be as blatantly obvious as you think. Hopefully jschieck's bug report will be of some help here.
     
    runevision likes this.
  23. jschieck

    jschieck

    Joined:
    Nov 10, 2010
    Posts:
    429
    So the root of my issue, and I suspect possibly some others in this thread, is not caused directly by using prefab variants. However, there is code that gets called when saving prefabs that creates a preview gameObject of the prefab like you'd see in the inspector preview window even if it's not actively selected. This will in turn execute any OnValidate code you might have, or just take some time because it has to actively Instantiate the prefab. I'm not sure if this is intended behavior to force OnValidate methods to get called or for some other reason, but it appears to be the main cause of the slow re-import process.

    Open your profiler and switch it to profile the editor, then hit File -> Save Project after modifying one of your heavy prefabs and you should be able to see and track down what specifically is causing your issue.
     
    andreiagmu and jrumps like this.
  24. Deleted User

    Deleted User

    Guest

    @runevision, is this somewhat familiar? When I edit anything on a prefab, Unity takes about 5 seconds for autosaving. This happens for every change I make and the variant is not even that large. This is what the deep profiler says about the editor, I couldn't go any deeper than that:

    Profiler Screenshot.PNG
     
    andreiagmu likes this.
  25. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    How long auto-save takes depends not only on the size of the Prefab that's being edited, but also on how many instances of that Prefab exist in currently open scenes, since each instance merges changes from the Prefab Asset whenever the Prefab Asset is saved.
     
  26. Deleted User

    Deleted User

    Guest

    It was only the master prefab in prefab mode. No scene was involved and if it was, there wasn't any instance, neither it, nor variants. I'll see if I can narrow that one down.
     
  27. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    I don't know what master Prefab means in your project, but if it's a Prefab that's used as part of other Prefabs, either because they nest it or because they are variants of it, then all of those get reimported as well when it's saved.
     
    Deleted User likes this.
  28. sniffle63

    sniffle63

    Joined:
    Aug 31, 2013
    Posts:
    365
    Same things happening to me on 2019.3.4

    It's horribly slow to make any changes to my prefabs or prefab variants. As others said, it can take 5-10 seconds some times and my prefabs are quite simple and I only have around 40 instances of them

    All I'm doing is working with ml-agents and some basic prefabs for a basic mlagent project.

    Turning auto-save off helps, but only by moving the lag to the end of editing when i click save. But, all its doing is some text file reading to merge metadata, so i can't see why it would take more than a second at the maximum for super complex objects. Really is a shame tbh
     
  29. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,460
    Editor Only samples are truncated by default. You can toggle their visibility in the cogwheel (three-dots in 2019.3) overflow menu of the Hierarchy view.
     
  30. Miguelfanclub

    Miguelfanclub

    Joined:
    Jun 14, 2015
    Posts:
    64
    BIG BUMP. This is insane. Somtimes I get the whole "hold on" window 3 times in a row straight. It can be as simple as pressing "Select" just to go to the parent folder. 2019.2.
     
  31. asger60

    asger60

    Joined:
    Mar 27, 2013
    Posts:
    45
    I'm experiencing the same issues as mentioned above. There was talk of a new version of Unity that would address prefab save times, but now I can't find it
     
  32. C-H-a-P

    C-H-a-P

    Joined:
    Feb 9, 2013
    Posts:
    4
    Thx to this thread this might be the issue for my editor slow-down as well.

    Using Unity 2020.x (no beta) with around 10 complex Prefab Variants as templates (sometimes even with nested other variants & multiple module-based component scripts) my Editor takes a refresh-nap for about 15 to 20 seconds each time something has changed.

    Yes, it's super annoying but on the other hand, this feature allows me super flexibility and I'm using it extensively for all my UI stuff.

    Hopefully, the Unity guys figuring something out to further improve the current Prefab serialization.

    (Right now I'm trying to eliminate unnecessary compile times with Assembly Definitions and/or Standard Assets folder strategy to get a minor workflow boost.)

    EDIT: Spelling
     
    Last edited: Feb 5, 2021
  33. C-H-a-P

    C-H-a-P

    Joined:
    Feb 9, 2013
    Posts:
    4
    Regarding my post above:

    I upgraded to 2020.2.3f1 and added asmdef files.
    At the moment, my editor experience seems to be a little more fluid as the recompile / re-import process has been reduced to 10-15 seconds (up from 15-20 seconds) as a number of scripts are left untouched.
    But I can't tell if it's just the editor upgrade, asmdef stuff, or something else.

    In any case: Prefab Variants for the win!
    Looking forward to upcoming improvements or suggestions! :)