Search Unity

Help Wanted How to stop game hitch from Loading a Large asset in Async method?

Discussion in 'Scripting' started by unitedone3D, Aug 19, 2021.

  1. unitedone3D

    unitedone3D

    Joined:
    Jul 29, 2017
    Posts:
    92
    How to stop game hitch from Loading a Large asset in Async method?
    Hey there!

    I have read lots of ambiguous information about this problem.

    If you have a large asset (say very heavy image texture/model/prefab) that loads using 'async' method it 'jams' the main thread and causes a hitch...now I thought this was fixed in Unity 2021...with using Asset Bundles streaming or Addressables, also using Streaming...but alas, I read that Streaming causes hitching if the asset is really big. Is it better to do this with multiple threads (multithreading)....?

    -Does ECS/DOTS solve this? -Is it only a I/O problem - needing a SSD/NVMe fast loading disk?

    Here are the possible solutions I found out: - Preload assets (preload everything, which of course will take a lot of memory), using the Preload slot - Preload by 'loading everything in front of the camera' - before the scene starts, so that it is all loaded in RAM (you just need to have the camera 'look' at the assets - and then they are in memory; they will
    hitch a 1st time..then they won't hitch anymore (in RAM memory) but you do that At the Start of the scene (won't matter because scene not started yet, still loading), before it starts you make a 'loading screen'/to hide it and then you do it (load it all and - destroy it all) then the scene starts - all the assets are in memory; no more hitching/hiccups when assets load. What I wonder about this technique is the prohibite memory cost to loading it All in memory from the start.. - LZ4H compression build, this specific compression is in 'chunks' based 'loading'...thus it seems that it only loads what it needs - that greatly reduces 'hiccup/hitching' while loading a spontaenous large asset in async method.

    What else is there to Stop those asset loading hitches/hiccups? I have read that this a limitation of Unity and many other engines too; How?? Do they get around this problem to make no hitches ever?

    ''Make small/smaller/reduce size of texture/reduce prefab/in little parts...'' that much can help..but we are talking about async loading a Very Large Asset/Prefab - in real time - with no hitching/hiccups - repeatedly/constantly.

    Thank you very much.

    PS: I read that it is down to Coroutine, threads, Main thread vs Multithread....like it's confusing what is suppose to be the Real reason why it hitches on loading a large asset...yes it could be anything, but after removing so many possible reasons and still experiencing hitching, it looks like a engine limit? As anyone broken that limit somehow? Are there other ways to at least minimize them/mitigate them to being almost invisible to the eye - because a hitch/stall/freeze - is Very visible?

    PPS: Found this: '' A common approach for multithreaded shader compilation is to have a background thread dedicated to it, with it constantly looking into a parallel queue to receive compilation requests, and putting the compiled pipelines into another queue that then the main renderthread will connect to the simulation. This is very important to do if you want to have an engine that doesn’t have a lot of hitching. Compiling shader pipelines can take a very long time, so if you have to compile pipelines at runtime outside of a load screen, then you need to implement such a multithreaded async compile scheme for your game to work well''

    Thus, is - MultiThreaded Async the real solution?

    PPS: I think I found the 'sort of' solution, which is a hardware one; games require precaching to avoid hiccups (because they are due to I/O hard drive loading speed too slow vs loading in RAM memory), I am not sure but when combining game precaching with multithreading (to trickle the data slowly on the main thread and load the rest on 'background threads'), this would stop hiccups; it can be done by creating a RAMdisk, and basically, precaching the largest files of the game (such as the resources.asset giga file that contains all the assets) on the RAMdisk; you would need sufficient RAM (64-128GB...to precache the 'whole' game in RAM); I have on the internet of people that did RAMdisk and after that - their Hitches were gone
    ...it was not related to video, CPU, GPU or anything like that..
    it was I/O hard drive/loading asset problem - from hard drive - into RAM - too slow - cause hitch. I see the parallel with Playstation 5's SSD hard drive and the UE5 demo that ran flawlessly (no hitching) it was due to the speed (of asset loading) of the SSD - to make for 'hitchless asset streaming' from disk; RAMdisk is the equivalent (by caching game on RAM), it will avoid hard drive I/O asset loading - causing hitch - the game will load - From RAMdisk, which is much faster than loading from a regular SATA hard drive. In PS5, it's the fast SSD technology, coupled with Fast DDR6 RAM. What I am wondering is if this has any impacy/bearing of singlethreaded vs multithreaded asynch loading...I am guessing the combination of RAMdisk + 128GB Fast RAM + multithreaded async + large page file would eliminate hitches.
     
    Last edited: Aug 19, 2021
unityunity