Search Unity

Prefabs.MergePrefabs on entering PlayMode takes almost 4 minutes

Discussion in 'Editor & General Support' started by NUKKschocke, Nov 26, 2018.

  1. NUKKschocke

    NUKKschocke

    Joined:
    Oct 17, 2018
    Posts:
    34
    My project takes almost 4 minutes to go into PlayMode. Same goes for going out of PlayMode, but I haven't gotten to that yet. Edit: Same Call, same amount of time on exiting PlayMode.
    Deep Profiling the process of entering PlayMode, I was able to get rid of a few logic loops that might've hindered my scripts. However, I DO need some tips on dealing with the elephant in the room.

    The Prefab.MergePrefab call at start.

    MergePrefabCall-01.PNG

    The weird thing is that the time allocated for the call in question is not the sum of its childrens' times. There is a LOT of functionality in this one call that is completely hidden from the user behind its name.

    Does anybody know what is happening here and how to reduce it?
     
    Last edited: Nov 26, 2018
  2. NUKKschocke

    NUKKschocke

    Joined:
    Oct 17, 2018
    Posts:
    34
    Sorry for bumping this a mere 24 hours after posting, but I'd really like some information about this. Even if it's just along the lines of "Your project setup is bad and you should feel bad. Nothing to be done about that, sorry."

    Bump.
     
  3. NUKKschocke

    NUKKschocke

    Joined:
    Oct 17, 2018
    Posts:
    34
    Another bump.
    Another weird thing is that this does not happen on my dev branch. It only affects the development and some other colleagues' branches. Might there be something wrong with the metadata or libraries?
     
  4. NUKKschocke

    NUKKschocke

    Joined:
    Oct 17, 2018
    Posts:
    34
    Bump.
    I have made a cross post over at Unity Answers.

    My current thinking is that this has something to do with a colleague's script that places a bunch of prefabs into the scene according to an FBX with lots of dummy objects (for position and rotation info). The prefabs are put under a parent object and then the parent object is prefabbed itself via script.

    Once I get all the subversion stuff done I'll see if breaking the parent prefab changes anything.
     
    CosmicBoy likes this.
  5. NUKKschocke

    NUKKschocke

    Joined:
    Oct 17, 2018
    Posts:
    34
    Bump.

    After some deliberation and trial-and-error, we have isolated the problem to definitely have something to do with the handling of prefabs in our scene. (This might seem like a no-brainer, but really having a definite focus for troubleshooting is a big step towards a solution)

    There is an object in our hierarchy called "Forests". This is the hierarchy of its children:

    Forests
    | - Phase0
    - | - forest-patch-0
    - - | - treetype0 (prefab)
    - - | - treetype0 (prefab)
    - - | - <lots of different trees, all instances of prefabs>
    - - | - treetypeX (prefab)
    - | - forest-patch-1
    - - | - <more trees>
    - | - <more forest patches>
    - | - forest-patch-n
    | - Phase 1
    | - <more phases>
    | - Phase n

    Because there is still not a good solution to merging large scenes, we decided to prefab the "Forests" object in its entirety in order to decouple it from the scene proper. This seems to be a grey area for Unity in regards to how it then tries to handle the "nested prefabs". In some way, the prefab instances of the individual trees get broken but in some ways, Unity still seems to recognize them on entering/exiting PlayMode and "do stuff" to them.

    Today, I broke the "Forests" prefab in the hierarchy and replaced all tree objects with their dedicated prefabs. Now play mode takes only about 10 seconds to start and exiting takes about the same time. This is a humongous improvement to the 340 seconds I started with.

    Now. This still doesn't explain why my branch was still working fine even with "Forests" still being a prefab in my scene but I'm not gonna be complaining about results here.
    I'll keep an eye on this and update accordingly.
     
    Nykster and CosmicBoy like this.
  6. CosmicBoy

    CosmicBoy

    Joined:
    Apr 16, 2014
    Posts:
    33
    @NUKKschocke thank you for following up on this post, we had the same problem and found the culprit thanks to this thread
     
  7. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    463
    @NUKKschocke Hi thanks for the post but I'm a bit lost as to what you did exactly.
    The hierarchy you posted already appears to have its tree as prefabs.

    Do you mean you eliminated all cases of prefab nesting?
     
  8. NUKKschocke

    NUKKschocke

    Joined:
    Oct 17, 2018
    Posts:
    34
    Due to never having figured out exactly what caused the original problem, my posts read a bit confusing. Sorry about that.

    Yes. Basically, in order to fix the problem, I eliminated all cases of prefab nesting by restructuring the entire hierarchy of the "Forests" object to its original state in which only the individual trees were instances of prefabs. This fixed the issue that seems to have been brought on by Unity on some level "recognizing" nested prefabs before it was a feature and getting somewhat confused.

    (Note: This was long before switching the project to a Unity version that supports nested prefabs)

    ... does this help a bit?
     
  9. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    463
    Haha, yes but not as much as I would have hoped.

    From what you're saying that fix is only relevant for unity versions without the new prefab workflow. I'm on 2018.4, so I'm back to square one on this one :confused:

    Thanks for clarifying!
     
  10. Gua

    Gua

    Joined:
    Oct 29, 2012
    Posts:
    440
    Do any of you use ProBuilder?
     
  11. NUKKschocke

    NUKKschocke

    Joined:
    Oct 17, 2018
    Posts:
    34
    Negative. Not in the project in question at least. But I've read about prefabs generated with ProBuilder slowing down the editor operations significantly. (f.e. the SNAPS prototype assets did that for me)

    The current workaround is to break the prefab instances / unpack the prefabs.
     
  12. eatbuckshot

    eatbuckshot

    Joined:
    Jan 10, 2016
    Posts:
    23
    I've encountered the "Prefab.MergePrefab" issue where it took almost a minute on entering playmode freezing the editor. Interestingly enough, it wasn't even a "nested" prefab but just having one prefab that contained a single merged probuilder mesh, the one and only game object in this prefab that caused it. Breaking it and putting that one merged probuilder mesh into the scene directly bypassed the MergePrefab problem.

    Edit: Despite it appearing as just one gameobject in the hierarchy, Probuilder stores all the mesh data in the script, so looking at the raw prefab contents reveals that it is quite large at being 4 MB of text, in my case, for a level design

    It appears this issue is described here
    https://forum.unity.com/threads/pb-...improved-prefab-workflow.600166/#post-4362187
     
    Last edited: Oct 4, 2020
    sejun_unity likes this.
unityunity