Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

How does "Preloaded Assets" in Player Settings Work?

Discussion in 'Documentation' started by alan-lawrance, Apr 12, 2015.

  1. alan-lawrance

    alan-lawrance

    Joined:
    Feb 1, 2013
    Posts:
    283
    Unity 5 has a new field in the Optimization section of "Other Settings" for Standalone builds:

    Preloaded Assets

    I've been unable to find any documentation that explains how this works. Presumably the memory you allocate for this gets used to permanently load assets, but is there any way to know which ones?

    Edit: Never mind, I see the "Size" is the number of array elements, and you can specify a list of assets. I had assumed the Size was a memory value in bytes.
     
    Last edited: Apr 12, 2015
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,445
    You're correct that this is not documented at all, we just used it without even thinking about it too much.

    When we ported our game to WebGL, we used streaming. This means that not all scenes and data is loaded when the game is already playable.

    As such, it may be possible that you get into scenarios where a scene was loaded but some assets it needs that are loaded dynamically (e.g: Resources.Load) will not be ready.

    To avoid this, we added these assets to "Preloaded assets". The engine then makes sure these will be ALWAYS AVAILABLE from the second the game starts.

    We did this for a couple of important data assets that had to be used early on in the game initialization.
     
    alan-lawrance likes this.
  3. ScorpioGamer

    ScorpioGamer

    Joined:
    Oct 14, 2012
    Posts:
    5
    @liortal So using "Resources.load" will not give any hiccups if you preload them via build settings?
     
  4. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,445
    Depends on what you mean by "hiccups".
    That setting means that the player will handle loading these assets by itself, before the player starts.

    This will add some loading time of course.
     
  5. ScorpioGamer

    ScorpioGamer

    Joined:
    Oct 14, 2012
    Posts:
    5
    occasionally i get spikes when i use "Resoures.load" for the first time, i use pooling after that. So i think preloading might help me there.
     
  6. itheark

    itheark

    Joined:
    Jul 1, 2015
    Posts:
    2
    Did it help by preloading or do i have pool the assets ??
     
  7. ScorpioGamer

    ScorpioGamer

    Joined:
    Oct 14, 2012
    Posts:
    5
    you will still have to pool it.
     
  8. Ratboy601

    Ratboy601

    Joined:
    Jun 22, 2014
    Posts:
    29
    So I assigned some models to my preloaded assets, and then they showed up blue (no texture/material) in game. So I removed them. Now they are still blue. Any ideas how to fix this?

    ========EDIT===============

    It would appear this problem had something to do with my changes to the vertex compression settings, or something else in the Optimization GUI, and not the preloaded assets at all. Thanks anyway!
     
    Last edited: Oct 23, 2015
  9. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,525
    Do you mean ScriptableObjects?

    I have added a couple of ScriptableObjects to the Preloaded Assets list but they are not being loaded at player start up (their OnEnable is not being called).
     
  10. Gametyme

    Gametyme

    Joined:
    May 7, 2014
    Posts:
    581
    Bump! Never did figure this one out.
     
  11. Carterryan1990

    Carterryan1990

    Joined:
    Dec 29, 2016
    Posts:
    78
  12. XCO

    XCO

    Joined:
    Nov 17, 2012
    Posts:
    366
    bump
     
  13. UnityUser9860

    UnityUser9860

    Joined:
    Dec 8, 2015
    Posts:
    179
  14. mukulabdagiri

    mukulabdagiri

    Joined:
    Jul 1, 2016
    Posts:
    11
  15. shahroz

    shahroz

    Joined:
    Jun 23, 2014
    Posts:
    1
  16. UnityUser9860

    UnityUser9860

    Joined:
    Dec 8, 2015
    Posts:
    179
  17. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
    Bump party!
     
  18. Carterryan1990

    Carterryan1990

    Joined:
    Dec 29, 2016
    Posts:
    78
    lmao unity is trolling us
     
    FlopCoat likes this.
  19. E2R_Ben

    E2R_Ben

    Joined:
    Oct 30, 2009
    Posts:
    143
    (bump?!) Would this work for assets in the streaming assets folder in a web GL build? I have a small bug where videos in my web gl project get stuck loading (they are all streamed through streaming assets) and wondered if this would fix it.
     
    shoo likes this.
  20. ttmmiizz100

    ttmmiizz100

    Joined:
    Mar 16, 2018
    Posts:
    11
  21. DenisK_WRG

    DenisK_WRG

    Joined:
    Oct 16, 2018
    Posts:
    12
    ВИМР
     
  22. bez01908

    bez01908

    Joined:
    Sep 23, 2018
    Posts:
    1
    BUMP! this hasn't helped me at all! I've been getting this problem where when I play my game a grey screen appears before my splash screen (for a good 20 seconds). so I arrivedd here to check if it would actually speed my launch screen up! but.. BUMP! nothing! again been sat here for almost 5 hours trying to find a solution :'(

    is there a way to have a something else displayed there to keep gamers engaged before they get impatient and switch off to another app.
     
  23. Carterryan1990

    Carterryan1990

    Joined:
    Dec 29, 2016
    Posts:
    78
    How large is your game? It could also be shaders/textures/objects loading. A lot of times a bunch of stuff you arent even using is included in your builds. You should check the editor log and see if there is stuff that's in there that you arent using it could help with load times.
     
  24. marcin-matczak

    marcin-matczak

    Joined:
    Sep 5, 2018
    Posts:
    6
    BUMP i just get a meaningless error when I try to load my ScriptableObject asset. It is in preloaded assets.
    Code (CSharp):
    1.  UnityEngine.Resources:LoadAll()
    2.     UnityEngine.Resources:LoadAll(String)
    3.          DefaultsStorage:get_Instance() (at .../DefaultsStorage.cs:27)
     
  25. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,525
    This is now working in editor and on device.
     
  26. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    382
    Which version? It doesn't work in editor in 2018.4.6.
     
  27. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    382
    Doesn't work in editor in 2019.2.15 either. :(
     
  28. emmy20

    emmy20

    Joined:
    Dec 8, 2019
    Posts:
    1
    BUMP..!!
     
  29. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,525
    Works for me with a ScriptableObject in 2019.2.13. The SO gets loaded on running in both editor and on iOS device.
     
  30. Radu392

    Radu392

    Joined:
    Jan 6, 2016
    Posts:
    210
    Sigh... bump. Could we get some documentation on this please?

    Are preloaded assets preloaded in one frame or is it an async operation? I'm looking into moving some of the loading times into the main menu where nothing happens, in which case async would be nice. If not, then it wouldn't be of any use to me.
     
  31. clashit256

    clashit256

    Joined:
    Dec 13, 2019
    Posts:
    2
    Still waiting on the documentation... can someone please?
     
  32. krugz_he

    krugz_he

    Joined:
    Nov 16, 2018
    Posts:
    1
    Holy bump! Pretty please? A little more explanation would mean so much.
     
  33. Freznosis

    Freznosis

    Joined:
    Jul 16, 2014
    Posts:
    275
    If anyone is still having trouble with this like I was, there is a page in the documentation that helps those of you trying to load ScriptableObjects. The example shows how to automatically add them to the preloaded assets after creating them. This is very useful because automation is your friend! I'm using this now and it works like a charm.

    https://docs.unity3d.com/ScriptReference/PlayerSettings.GetPreloadedAssets.html

    For those that aren't using this for ScriptableObjects, Unity made the GetPreloadedAssets a UnityEditor function. So as of right now I don't believe there is anyway to directly get those assets at runtime. I have a feeling this is because the assets are pre-loaded but not kept track of after being pre-loaded the way they are in the editor (Or there is a possibility the editor list is strictly for loading and not referencing). I haven't found enough information on this to really say whether or not the list can be used in a build, but using it for ScriptableObjects works great.

    Perhaps a workaround can be to have a ScriptableObject with a List of Prefabs you want to pool. You could pool these at the very beginning of the game (the moment your ScriptableObject is pre-loaded) using OnEnable. Of course it's not ideal, but I don't see why it wouldn't work, and it would give you some more flexibility. Also referencing a ScriptableObject will allow you to reference almost anything else in your game without having to clutter the PreloadedAssets list.

    If you are using a version below 2018.2, you can check out this script on GitHub that uses Reflection to help you out.
     
unityunity