Search Unity

Unity Level Streaming

Discussion in 'General Discussion' started by hippocoder, Mar 19, 2014.

  1. goat

    goat

    Joined:
    Aug 24, 2009
    Posts:
    5,182
    Regardless you'd still be able to stream files from the net...into local storage. The overwhelming amount of assets would still be shipped with the game of course...streaming makes it work better.
     
  2. paintbox1

    paintbox1

    Joined:
    Jan 20, 2014
    Posts:
    36
    Oh, Im sorry then. I thought you were talking about advertising in your essay.
     
  3. Jarhead

    Jarhead

    Joined:
    Jul 4, 2009
    Posts:
    38
    Even if they revamp the streaming system, you still need to create instances of prefabs, once they are streamed in, which can still be a bottleneck even now. Yes you can spread instantiate across multiple frames and make smaller prefabs, etc. However, even with all of that, if you have to instantiate many prefabs it can still be an issue. It would be nice to have the ability create instances of prefabs in an async manner, which I think would be very useful for streaming. I'd like to know if the new jobs system will support this.
     
  4. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,191
    The Async load methods do not use Instantiate at all, so I am not really sure where you are coming from here.

    Yes, you can stream in one prefab and then instantiate it to make copies, but you can also just stream in multiple copies if you need them, avoiding Instantiate completely.
     
  5. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,191
    This is a fantastic idea! Right now when a game object is streamed in, I have to wait for one frame after it's "loaded" and then manually search for it via (using FindWithTag currently). There are probably other methods that can be used as well, but none of them would be as simple as simply hooking a delegate straight into the streaming pipeline.

    Perhaps it could even work with Tags. IE., you specify whether the delegate should be called for all tags, or only when the streamed game object has a specific tag.
     
  6. sandboxgod

    sandboxgod

    Joined:
    Sep 27, 2013
    Posts:
    366
    Normally async resource loaders never provide that for you. Because the loads happen in another thread. The other thread can't just call right back into main thread and invoke a delegate. Trying to think though- in C# they have InvokeMethod and so forth. I've only used that method once. Just explaining it's usually not a straight forward thing. In C++, you always cycle and check to see if all the resources are loaded. In C#, its a possibility. Just depends on what they are doing under the hood.
     
  7. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    They could always use some kind of execution-fiber-style system, where the background loading thread after loading everything sort of "schedules" a function to be called on the main thread (which, presumably, would trigger a delegate or something that you could hook into)
     
  8. sandboxgod

    sandboxgod

    Joined:
    Sep 27, 2013
    Posts:
    366
    @PhobicGunner, thank you that sounds like a good suggestion. Wasn't familiar with that term at all
     
  9. Cynicat

    Cynicat

    Joined:
    Jun 12, 2013
    Posts:
    290
    Dear Unity Devs.

    i've been wanting to know about unity 5's level streaming. i understand if you cant comment on it but if you could that would be great.

    1. does it work while in the editor?
    2. can it be controlled through scripts
    3. how much control will we have? (can i load based on world position, trigger areas, etc...)

    Tips: allow us to set up our own systems and also allow us to control it all through scripts.
    a simple Streaming.LoadAssetBundle("DungeonRoom2"); with some callbacks for stuff like streaming started streaming, finished streaming asset, finished streaming bundle. this way we could make a trigger that called this command or a more complex system. ALSO: please let us control asset bundles in the editor. Example: please make it so i can write an extension that puts my object into the appropriate asset bundle based on the position without my help. then i can also write one for loading and unloading the bundles based on editor camera position.
     
    Last edited: Jun 27, 2014
  10. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    What you load is driven by script code. You simply use Application.LoadLevelAdditiveAsync and it will load a level. If you wrap that call into a script that loads things based on position or something else is entirely up to you.

    Unity simpy makes sure that the load happens in the background.
     
  11. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    We have done some work on that but it's not ready for 5.0 yet. It's going to be in a later 5.x release.
     
    superpig likes this.
  12. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Hard to say without a project folder to profile. But we have done some optimizations especially in the culling code.
     
  13. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    We have tried a couple of things to make async texture upload faster on all platforms. We took some dead-ends but in the end, the biggest problem was that the approaches we took were triggered from the main thread / loading thread, and that lead to unpredictable memory consumption & not being able to accurately timeslice the uploads.

    What we are now working on (for 5.x not 5.0) is on the loading / main thread we send texture upload commands in the form of string path, int offset, int size; to the render thread. The render thread has a ringbuffer of reusable temporary memory into which we load the textures. The upload instructions can be sent through a queue that can be called on any thread thus the upload can be triggered directly from the loading thread.

    The render thread then triggers an async read and when it completes it uploads it. By having the control in the render thread, we can control memory consumption and timeslicing accurately. This will get rid of hiccups caused by large texture uploads.

    We are planning to expose some simple API's around this as well:

    // This forces the loaded mip level to a specific mip level.
    void Texture2D.LoadMipLevel (int mipLevel);

    // Can be setup in the importer, so you can make a texture not be uploaded at all until you call LoadMipLevel explicitly.
    bool Texture2D.automaticallyLoadTextureData

    Those will not be in 5.0, but we are looking at it for 5.x.


    On top of this more high level systems for texture streaming could be built, but first we will expose the low level loading primitives to scripting.
     
    hippocoder and superpig like this.
  14. shkar-noori

    shkar-noori

    Joined:
    Jun 10, 2013
    Posts:
    833
    Are you serious?
     
  15. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,051
    And what about when you use WWW and WWW.LoadImageIntoTexture?? If you download a big texture you get framerate drops when it executes LoadImageIntoTexture method.

    Sometimes it's impossible to use AssetBundles because it's external data from a WebService that it's not controlled by us. And also because AssetBundles are not compatible between Android and iOS and we don't have time (budget) to spend generating all this stuff and publishing two versions.

    It's going to be something to be asynchronous and don't freezes games?
     
  16. deram_scholzara

    deram_scholzara

    Joined:
    Aug 26, 2005
    Posts:
    1,043
    If you don't have time to publish two versions (iOS/Android), then AssetBundles aren't an issue anyway.

    Asset Bundles generation can (and should) be automated. Usually the best way to do it for multiple platforms is to export in batches based on platform. Set up your Asset Bundle generation script such that it exports all needed bundles for iOS, then it exports all the bundles for Android.

    Once they're generated, you put them in platform-specific directories like:
    http://mycompany.com/mygame/streamingassets/ios
    http://mycompany.com/mygame/streamingassets/android

    It's not that complicated, and the amount of time the Asset Bundle generation consumes is entirely dependent on how many bundles you have to export. And since it's automated, you don't need to sit around waiting for it - you can go see a movie, or do it while you're asleep.
     
  17. Cynicat

    Cynicat

    Joined:
    Jun 12, 2013
    Posts:
    290
    thanks for the reply =3

    two more clarifications please.

    can stuff be streamed in by an editor extension?
    can i devide my objects into groups in the editor(via editor script)?

    thanks in advance!
     
    Last edited: Jun 27, 2014
  18. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,349
    That makes sense and is the next logical step to provide realistic streaming wihtout pauses

    Very nice :)
     
  19. Woodlauncher

    Woodlauncher

    Joined:
    Nov 23, 2012
    Posts:
    173
    Any answers on this from Unity?
     
  20. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,191
    In my current project, the biggest hitch when using Application.LoadLevelAdditiveAsync comes from Mesh.Bake PhysX CollisionData, as I am loading a somewhat large mesh terrain that uses a mesh collider.

    So, will the collision data calculation also be performed on the loading thread? I'm assuming yes, since without this optimization there will continue to be massive hitches when using the Async loading methods, but confirmation would be great.

    By the way, as it stands now with the scene I am trying to load, LoadLevelAdditiveAsync performs roughly the same as Instantiate. That is just ridiculous. Maybe it was stupid of me, but one of the main reasons I originally purchased Unity Pro was for this feature, so the fact that it doesn't work as advertised is pretty disappointing.

    If possible, the changes that make this feature work as intended in Unity 5 really need to be patched into Unity 4. I cannot harp on this enough.
     
  21. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Well if you're quick, the upgrade is still cheap afaik :)
     
  22. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,191
    I've actually already purchased Unity 5 Pro, so in terms of my own projects this isn't an issue.

    Unfortunately, I have an Asset Store Package (see signature) that uses Async Loading (for Pro users), and I can't expect that all of my users will upgrade to Unity 5 Pro.

    While I am upfront about the issues with Async Loading, it would be great if these users would be able to take full advantage of a feature that is advertised to work with Unity 4 Pro.
     
  23. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I think I had a bit of a moan about that to Unity privately before but if I recall, Unity did actually do what they said they would, but I misunderstood exactly what it was.
     
  24. cl9-2

    cl9-2

    Joined:
    May 31, 2013
    Posts:
    417
    Is this still the case with Unity 5 Beta?
     
  25. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,191
    I'm not sure what you mean. Here's the text from the Application.LoadLevelAdditiveAsync page:

    This has been up on that page for over two years. "Without any hiccups in game play," is a pretty strong statement, and I don't think it's open to interpretation.

    @cl.9 I'm not using the beta, so I'm not sure. Hopefully someone else who is can chime in!
     
  26. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,191
    Well, according to some testers it appears the same issues with level streaming exist in the Unity 5 beta. Very disappointing.

    Thread
     
    cl9-2 and Trigve like this.
  27. Cynicat

    Cynicat

    Joined:
    Jun 12, 2013
    Posts:
    290
    pretty sure the level streaming isnt coming till the scene manager update
     
  28. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,191
    That's nice to hear. Hopefully you're right!
     
  29. Gooseman_1977

    Gooseman_1977

    Joined:
    Aug 15, 2013
    Posts:
    89
    I dream of the day we can have content streaming similar to UE3.. The way the load/unload content is amazingly seamless, and has almost nil performance implications.
     
    shkar-noori likes this.
  30. Cynicat

    Cynicat

    Joined:
    Jun 12, 2013
    Posts:
    290
    lol do you remember ue3's streaming? i remember it being a little glitchy with some serious performance impacts. i always had to make a small simple area to occupy the player long enough to load the next area. same thing that unity has at the moment.
     
  31. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Is there any documentation on how to create AssetBundles in Unity5beta?
    Seems there´s a new feature:

     
  32. mfindlater

    mfindlater

    Joined:
    Aug 23, 2012
    Posts:
    7
    I don't know about documentation but there is this:
     
  33. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    I'm necroing this thread to see if anyone or if anything has been blogged, written, documented now on how to deal with streaming...

    especially related to Enlighten and precomputed chunks...

    would be really helpful.
     
  34. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,191
    Good idea tswalk. As far as I'm aware the streaming system is not actually in place. At least, I haven't seen a single thing relating to it mentioned recently. I'll be experimenting with lightmap baking and how that works with async loading within the next week or two.

    In addition to your suggestion, I think it would be a great idea to document experiences with the Async loading methods in Unity 5. There are definitely speed increases, but I still have doubts that these methods are able to deliver on their glorious promise of creating completely streaming worlds without any hiccups in game play.

    For example, I am trying to load a terrain with a 2049 height map resolution (2048 for other resolutions) using Application.LoadLevelAdditiveAsync. This is must faster in Unity 5 than Unity 4, but it's not without a hiccup or two. Here are the performance hogs according to the Profiler (and yes, this is tested on a Windows Standalone build).

    Frame 52165 - GFX.WaitForPresent: 61.78 ms
    Frame 52235 - Shader.Parse: 12.20 ms (acceptable)
    Frame 52241 - Shader.Parse: 22.19 ms
    Frame 52242 - Shader.Parse: 42 ms
    Frame 52243 - TerrainData.AwakeFromLoad: 98.26 ms
    Frame 52247 - UpdateDepthTexture: 62.94 ms

    Some of these might already be fixable or issues relating to my specific project. Hopefully others will post their experience and we can figure out what's correctable by us (the user), and what can be improved by the Unity developers.

    I still don't get why some of this stuff, such as awakening the terrain data from load, has to be done in a single frame. As a user, I have already accepted and taken into account the fact that this process is not going to be immediate. Why not spread the actual process of loading stuff into the scene over multiple frames? Is it just not possible?
     
  35. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    I think this is why we need some official guidance from Unity on the subject... as we can only guess how it was designed to work versus our idea of how we think it should.

    something practical that exemplifies how to break a scene down and prepare it for streaming.. then, how to handle that stream on the loading end.
     
  36. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Hi,

    First of all LoadLevelAdditive and Enlighten does not currently work. We are working hard on getting that fixed and shipped as fast as possible.

    In Unity 5 we have moved even more loading of data away from the main thread which is why you are seeing an improvement but there are still things that needs to be done on the main.

    The work that needs to be on the main thread has been time sliced, but you cannot time slice the uploading of a single texture to the graphics card, so large textures will still cause hiccups. As you have noticed a large terrain will upload a large basemap texture.

    There are still areas where we can do improvements and we certainly will, but until that is ready to ship the recommendation is to keep an eye on your texture sizes, including those used by terrain, try to make sure all shader variants have been loaded and maybe try to ensure your user is in an area where the hiccups are less noticeable.
     
    tswalk likes this.
  37. thxfoo

    thxfoo

    Joined:
    Apr 4, 2014
    Posts:
    515
    I just wanted to add something more that should be done with time-slicing: Runtime-Navmesh-Generation.

    If you have a large world, e.g. 100 square miles, then the Navmesh is many gigabytes, so you have no choice but to generate it at runtime on loading a specific LOD-level chunk. Since this eats CPU away it should also be time-sliced.

    Thanks
     
  38. thxfoo

    thxfoo

    Joined:
    Apr 4, 2014
    Posts:
    515
    Why?
    Can you not create an empty texture and use something like glTexSubImage2D but for upload, to upload it in multiple frames?
    Or the ugly one: upload 4 textures and use render2texture to create a single one from it.
     
  39. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,191
    So does that mean high resolution terrains will always cause hiccups or is there still hope for the future?

    Also, what about physics calculations on meshes? Can those be time sliced on the main thread?
     
  40. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    We have been looking into a solution where we would upload the mipmap levels one at a time, or based on some heuristic we would upload the best fitting mipmap level first. I am not sure what we end up doing or when it will ship
     
  41. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    There is hope but no time schedule for it yet.

    I don't know about physics.
     
  42. gilley033

    gilley033

    Joined:
    Jul 10, 2012
    Posts:
    1,191
    Thanks for taking the time to respond. I (and I'm sure others) appreciate it!
     
  43. NatureManufacture

    NatureManufacture

    Joined:
    May 20, 2014
    Posts:
    2,026
    At the moment I could offer you a streaming system. https://www.assetstore.unity3d.com/en/#!/content/36486 We released it yesterday. Few clicks will split your scene in to the parts and make it ready to stream. If there will be any questions - contact us. System was made using expierence which we gained while creating MMO Games. It's suitable for mobile , webplayers and pc/mac.
     
  44. Dan2013

    Dan2013

    Joined:
    May 24, 2013
    Posts:
    200
    @Joachim_Ante @superpig @Tomas1856 @hippocoder
    @SteenLund @Mikko Mononen @Graham Dunnett
    @NatureManufacture

    This is a very informative thread. I am wondering if some improvements are already included in Unity 5.2 or Unity 5.3 (that will be released several days later).

    For example, I saw improvements for Resources.UnloadUnusedAssets() are mentioned in this thread.
    Are these improvements above included in Unity 5.2 or 5.3?

    In another thread, a Unity dev, Tomas1856, said that Resources.UnloadUnusedAssets() calls GC.Collect(). Does that imply that some (even very small) spike/lag usually happens because of calling it? I know that some people cause it during their loading-screen scene. Is that appropriate to call it in a game-play scene?

    What is the best practice to avoid spike/lag when calling Resources.UnloadUnusedAssets() now?
    Suppose I have several very big GameObjects (BigObjectA, BigObjectB, BigObjectC) that hold references to expensive resources.
    A good unloading solution is to unload them one-by-one like this below?
    Destory(BigObjectA); UnloadUnusedAssets(); wait some time;
    Destory(BigObjectB); UnloadUnusedAssets(); wait some time;
    Destory(BigObjectC); UnloadUnusedAssets();

    Or, just unload them all like this below?
    Destory(BigObjectA);Destory(BigObjectB); Destory(BigObjectC); UnloadUnusedAssets();


    I also have a question about Applicaiton.UnloadLevel.
    If I use Application.LoadLevelAdditiveAsync("SceneA") to load a scene, and set all loaded objects of the scene as a child of one single object, SceneObjectA. Then, is there any different between calling Destory(SceneObjectA) and calling Applicaiton.UnloadLevel("SceneA")?
     
    Last edited: Dec 6, 2015
  45. Dan2013

    Dan2013

    Joined:
    May 24, 2013
    Posts:
    200
    Oh, I saw Unity 5.3 just made some scene-loading related updates including multiple-scene editing and SceneManager.
     
  46. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    Now ,can make open world with this level streaming?which api support?
     
  47. NatureManufacture

    NatureManufacture

    Joined:
    May 20, 2014
    Posts:
    2,026
    You could even at unity 4. I setup gloria victis mmo on my world streamer. At unity 5 its pretty good at 2017 even better. Only light probes need some tricks.
     
  48. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    Is using loadLevelAsyc or load assetbundlle for level? how to make not jiggle when instianate the abundle resources?
     
  49. Mariusz-Born7

    Mariusz-Born7

    Joined:
    Sep 4, 2015
    Posts:
    40
    So many years have passed and there is no good async level streaming. SceneManager.LoadSceneAsync (Additive) causes hiccups. First part of the process (up to 0.9 progress) is ok, but the last part where "Application.loadLevelAsync Integrate" and "Loading.awakeFromLoad" are called, suck big time! Placing 10k cubes in a scene, containing a simple empty script (without Awake and Start methods), causes frame drop and hiccup. The integrate part should be spread on many frames in order to not lag! Don't know why Unity ignores this problem.
     
  50. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    Seeing this thread necro’d makes me feel a little better about my development in Unity.

    There was a time when @hippocoder was still learning too.
     
    hippocoder likes this.