Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity3D AssetDatabase.LoadAssetAtPath() vs Resource.Load()

Tags:

unity3d

My partner in game dev are looking at Unity. I dynamically loaded an asset using Resource.Load() and he used AssetDatabase.LoadAssetAtPath(). They both seem to work so which one should be used? Why have 2 different ways to dynamically load assets?

like image 848
user441521 Avatar asked Sep 08 '17 00:09

user441521


1 Answers

AssetDatabase.LoadAssetAtPath() vs Resource.Load() ...They both seem to work so which one should be used?

None of them.

Your partner will end up with a game that he cannot build because he used AssetDatabase.LoadAssetAtPath(). The AssetDatabase.LoadAssetAtPath() function came from the UnityEditor namespace which is only used to make Editor plugins. It won't work outside the Editor and it won't even let you build your game at-all.

You using Resource.Load is fine but Resource.Load requires the use of the Resources folder which is known to cause slow down loading time of the game.


AssetBundles is the recommended way. You can put those files in the StreamingAssets folder then use the WWW or AssetBundle API to load it during run-time. You can learn more about how to use AssetBundles here

like image 112
Programmer Avatar answered Nov 10 '22 23:11

Programmer