- Home /
Performance of Resources.Load vs Direct Reference vs Resources.LoadAsync for large level assets
Hi,
I was wondering if I could get a straight answer from someone on this question. The forums all say different things. What is the best way to load large assets at runtime? Direct reference in a script or Resources.Load? I know technically Unity supports direct reference so that the build will know what assets to not include. I use direct reference for most assets in my game. However I have around 85 levels (represented by scriptable object files) and I don't really want to load all 85 of them at once, especially since they have large prefabs attached--but I know I definitely want to load them at some point one at a time. In this case, is it better to use Resources.Load? Or should I pile them all onto a "resources" GameObject I put in my initial scene with DontDestroyOnLoad? Seems like that method would eat up a bunch of memory, unless Unity will automatically handle what's not being used?
I have currently tried a few options with Resources.load, which all ended horribly since Unity5. Especially on Android. Even in my smallest level, with really nothing in it--Resources.Load will take around 12 seconds. I used to use Resources.LoadAll in a certain folder at app start, and that made my app launch last around 20-30secs. The thing is, after the first use of Resources.Load, any subsequent use is pretty fast--it turns into what I'd consider to be normal load times.
I'd really like to launch my game, but this is becoming a nasty issue. With Resources.Load, it's looking like I inevitably have to suffer a long load time somewhere in my user's first 2 minutes--which is the most important window for capturing users. It'd be great to get some guidance here. Some forums say it's better to use direct reference regardless of asset size..but this is a lot of large assets.
What about Resources.loadasync?
I'm experiencing a similar issue with Resources.LoadAll on Android devices. Depending on the device it can take 12+ seconds to complete. I'm currently looking at alternatives but i can't find much about it's poor performance. I'll try Resources.LoadAsync to see if that helps any. I've also been looking at loading my resources using the AssetDatabase methods but I'm not sure if it'll work correctly.
Answer by Xarbrough · Sep 05, 2016 at 09:18 PM
Reference is faster than Resources.Load. The Async variant can help if you want to load something in the background. However, it sounds unlikely that the load time alone takes 12 seconds. How big exactly is it? You can load quite a few megabytes in 12 seconds, so it's much more likely that some instantiation code or anything running in Awake or Start slows things down. Have you profiled your game in the editor and on device? You will need to start the Profiler in a different scene before you can record any calls made in Awake, since this is when the Profiler is created. What's the target hardware?
Maybe there is some issue with how you are loading or creating things, if not, then you probably are looking for multiple optimizations: smaller textures, fewer geometry, smaller hierarchy, etc.
Your answer
Follow this Question
Related Questions
Help performance issues 0 Answers
Asset bundles and scene references 1 Answer
Assetbundle loading time 0 Answers
Scriptable Object references if not saved in AssetDatabase? 1 Answer
How do I load music optimally? 0 Answers