Search Unity

Enter Play Mode takes 20-30 seconds

Discussion in 'Entity Component System' started by Thygrrr, Jun 9, 2020.

  1. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    700
    I use Unity 2020.1 beta 11 on a reasonably decent Windows 10 machine. Unity & the Project loads faster than it takes to enter play mode.

    I use Entities 0.11, Hybrid Renderer V2, Unity Physics
    My scene has 2 (complex) gameobjects that get converted (between 850-900 entities total, some fairly simple meshes and colliders, and basically a few dozen objects from a nested prefab, with 3-4 children each.)

    Entering Play Mode is excruciatingly slow - it usually takes around 30 seconds, sometimes 1-2 minutes. Sometimes it's fast, 5 seconds or less. It seems to SOMEWHAT be related to how my subscenes are loaded (current setup just has the GameObjects with a ConvertToEntity behaviour on them), and what my burst and livelink settings are.

    This is close to an "empty" project, basically a few cameras, two spaceships, a skybox, and a planet.

    If I remove the two objects that are to be converted, entering play mode is almost instantaneous.

    Packages:
    Code (JavaScript):
    1. {
    2.   "dependencies": {
    3.     "com.unity.burst": "1.3.1",
    4.     "com.unity.collab-proxy": "1.3.7",
    5.     "com.unity.entities": "0.11.0-preview.7",
    6.     "com.unity.ide.rider": "2.0.5",
    7.     "com.unity.ide.visualstudio": "2.0.2",
    8.     "com.unity.ide.vscode": "1.2.1",
    9.     "com.unity.inputsystem": "1.0.0",
    10.     "com.unity.jobs": "0.2.10-preview.11",
    11.     "com.unity.nuget.newtonsoft-json": "2.0.0",
    12.     "com.unity.physics": "0.3.2-preview",
    13.     "com.unity.render-pipelines.universal": "9.0.0-preview.14",
    14.     "com.unity.rendering.hybrid": "0.5.1-preview.18",
    15.     "com.unity.scriptablebuildpipeline": "1.7.3",
    16.     "com.unity.searcher": "4.3.1",
    17.     "com.unity.test-framework": "1.1.14",
    18.     "com.unity.test-framework.performance": "2.2.0-preview",
    19.     "com.unity.textmeshpro": "3.0.0-preview.14",
    20.     "com.unity.timeline": "1.3.3",
    21.     "com.unity.ugui": "1.0.0",
    22.     "nuget.mono-cecil": "0.1.6-preview",
    23.     "com.unity.modules.ai": "1.0.0",
    24.     "com.unity.modules.androidjni": "1.0.0",
    25.     "com.unity.modules.animation": "1.0.0",
    26.     "com.unity.modules.assetbundle": "1.0.0",
    27.     "com.unity.modules.audio": "1.0.0",
    28.     "com.unity.modules.cloth": "1.0.0",
    29.     "com.unity.modules.director": "1.0.0",
    30.     "com.unity.modules.imageconversion": "1.0.0",
    31.     "com.unity.modules.imgui": "1.0.0",
    32.     "com.unity.modules.jsonserialize": "1.0.0",
    33.     "com.unity.modules.particlesystem": "1.0.0",
    34.     "com.unity.modules.physics": "1.0.0",
    35.     "com.unity.modules.physics2d": "1.0.0",
    36.     "com.unity.modules.screencapture": "1.0.0",
    37.     "com.unity.modules.terrain": "1.0.0",
    38.     "com.unity.modules.terrainphysics": "1.0.0",
    39.     "com.unity.modules.tilemap": "1.0.0",
    40.     "com.unity.modules.ui": "1.0.0",
    41.     "com.unity.modules.uielements": "1.0.0",
    42.     "com.unity.modules.umbra": "1.0.0",
    43.     "com.unity.modules.unityanalytics": "1.0.0",
    44.     "com.unity.modules.unitywebrequest": "1.0.0",
    45.     "com.unity.modules.unitywebrequestassetbundle": "1.0.0",
    46.     "com.unity.modules.unitywebrequestaudio": "1.0.0",
    47.     "com.unity.modules.unitywebrequesttexture": "1.0.0",
    48.     "com.unity.modules.unitywebrequestwww": "1.0.0",
    49.     "com.unity.modules.vehicles": "1.0.0",
    50.     "com.unity.modules.video": "1.0.0",
    51.     "com.unity.modules.vr": "1.0.0",
    52.     "com.unity.modules.wind": "1.0.0",
    53.     "com.unity.modules.xr": "1.0.0"
    54.   }
    55. }
    56.  

    I haven't been able to consistently improve this behaviour, and it is really slowing me down while prototyping. Any tips?

     
    Last edited: Jun 9, 2020
  2. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
  3. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    700
    This setting doesn't make a significant difference.

    I think it's the dependency resolution of when systems execute, maybe. I wonder how that can be so slow, but it really seems to get worse the more UpdateAfter attributes I use.

    (I have like a dozen fairly simple systems, really nothing fancy)

    The game runs at over 160fps burst compiled once it's loaded.
     
    Last edited: Jun 9, 2020
  4. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    700
    Ok I think this thread belongs in the DOTS forum instead.
     
  5. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    700
    I narrowed it down, if I place my objects in a sub-scene, the load time is drastically decreased unless I have the subscene, meaning it is, indeed, entity conversion.

    Entity conversion seems to choke on objects that:
    - contain a nested hierarchy of nested prefabs
    - have authoring components on multiple levels

    Tomorrow, I'll try to pre-register each of the prefabs (there's 5, and about 5-15 instances of each) somehow before conversion, stop the conversion and run a manual instantiation of the prefab entity.

    This really throws a spanner into my authoring workflow, but it might work out.
     
  6. PeppeJ2

    PeppeJ2

    Joined:
    May 13, 2014
    Posts:
    43
  7. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    700
    So this is my Gameobject hierarchy, and each of these (and probably 1 more page down) has similarly nested objects, each with their own authoring components.

    Doesn't it convert each prefab only once? Is these a shortcut way to do it, other than stopping conversion at one point and manually declaring/converting the nested prefabs?
    upload_2020-6-10_22-51-19.png
     
    Last edited: Jun 10, 2020
  8. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    700
    Oddly enough, it was about to show how even with just 1 object, it's never below 3 seconds (1.8 of which were spent by the entity conversion system)... that ship alone used to take 10 seconds. I didn't meaningfully change its architecture that I know of, was just getting started with my rearchitecting.

    But now, no matter how I do it, it all happens in <700 ms, which I feel is very acceptable.

    I'll investigate what's going on here, and why it is now faster than ever, even with 3x the content in the scene, or the subscene, or both.

    upload_2020-6-10_23-5-52.png
     
  9. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    700
    I did upgrade to Beta12 earlier today. hmm.
     
  10. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Skip domain reload on enter playmode should be enabled on any project that primarily uses entities for game code:

    https://blogs.unity3d.com/2019/11/05/enter-play-mode-faster-in-unity-2019-3

    On Dots Shooter we have roughly 0.5 seconds of enter play mode time.

    Structuring your scenes with subscenes and avoiding ConvertToEntity is critical for faster iteration speed otherwise all conversion code has to run when entering playmode. By using subscenes, all the conversion is cached on a per scene basis. Can't stress enough how critical this is for any real world large scale projects.

    ConvertToEntity is not something that should be used on any real world large project.
     
  11. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    700
    Interesting, thank you!

    How do I save my entities "as prefabs", i.e. "as assets" without conversion while maintaining the comforts of nested prefabs?

    They always seem to have to live in some kind of scene as some kind of gameobject.

    I'd love to just load them by addressable name, authoring them exactly once, for instance.

    (PS It's a real world prototype for a medium project)
     
    Last edited: Jun 10, 2020
  12. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    One option is to create a 'prefab' scene where you store all your prefabs, settings, etc.

    I'm sure there are other ideas floating around.
     
    florianhanke and Thygrrr like this.
  13. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    700
    How do I prevent these from getting injected into my main world, though? :)

    (Not sure what to search for, really... maybe something in the conversion system API?)
     
  14. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    700
    Ahhh I could run a prefab registry IConvertToEntity and have that just declare all the prefabs, not placing the objects.
     
  15. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Yeah, I'd create some type of 'prefab conversion' component that gives them the actual built in Prefab component, gives them an ID to store them in a map etc to setup however you generally handle your assets.

    Then you can just instantiate directly from the existing Entity, very fast, no conversion required.
     
    Last edited: Jun 11, 2020