Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Docs for AssetDatabase.LoadAssetAtPath variations are confusing

Discussion in 'Asset Database' started by cory_munky, Feb 9, 2015.

  1. cory_munky

    cory_munky

    Joined:
    Dec 10, 2014
    Posts:
    66
    "Returns the first asset object of type type at given path assetPath." vs "Returns the main asset object at assetPath." "Returns an array of all asset objects at assetPath." vs "Returns all asset representations at assetPath." These are all technically correct, but are so brief and so similar that they are hard to differentiate.

    Saying "Asset representations are objects in the asset that are visible in the Project view" is technically correct but it is not very helpful. It is very confusing until your absorb elsewhere that LoadAssetAtPath saying "Some asset files may contain multiple objects." indicates that what appears to be a single asset file can sometimes actually contain multiple assets (but most often does not). And, also you need to connect that LoadAllAssetsAtPath saying "This function returns all asset objects at a given path including hidden in the Project view" implicitly indicates that LoadAllAssetRepresentationsAtPath is not the complete set.

    Meanwhile, LoadMainAssetAtPath doesn't mention anything about the many-to-one asset-to-file relationship that it is trying to address. Neither do any of the Load*Asset examples. They all load a single texture asset from a jpg or png. There are no examples that address the existence of compound assets.

    Also, the relationship between different styles of loading assets vs what gets packed into an AssetBundle is very vague. Is there any difference between
    Code (CSharp):
    1. BuildAssetBundle(AssetDatabase.LoadMainAssetAtPath("foo.file"), null, pathName, CollectDependencies)
    vs
    Code (CSharp):
    1. BuildAssetBundle(null, AssetDatabase.LoadAllAssetsAtPath("foo.file"), pathName, CollectDependencies)
    ?? Or, what if I used CompleteAssets instead of CollectDependencies? Is there any difference then?

    If I use LoadMainAsset instead of LoadAllAssets, is it the case that AllAssets are still Loaded, but I don't get handed a direct reference to them? Or, is something different happening under the hood?

    If LoadAssetAtPath can only returns the first asset of a type at at path, I don't see any use case for it. If it's a compound asset (maya file), then I should iterate through the result of LoadAllAssetRepresentationsAtPath. If it's not a compound object (jpg), then I should LoadMainAssetAtPath. Is LoadAssetAtPath just for "I'm pretty sure there's only going to be one of that type in there... Hope I'm right!" cases or is there another use case I'm not aware of?

    Is LoadAllAssetRepresentationsAtPath specifically intended for making certain kinds of Editor UI plugins easier or are there other uses for it instead of LoadAllAssetsAtPath?
     
    neonblitzer likes this.
  2. neonblitzer

    neonblitzer

    Joined:
    Aug 5, 2013
    Posts:
    13
    Semi-off-topic:
    What's the purpose of the EditorGUIUtility.Load function (and the Editor Default Resources folder it uses) since we can load assets from any folder with AssetDatabase anyway? Resources.LoadAssetAtPath was removed so backward compatibility apparently isn't an issue.
     
    Last edited: May 15, 2023
  3. duck

    duck

    Unity Technologies

    Joined:
    Oct 21, 2008
    Posts:
    358
    Hi,

    We're aware that there are now (and always will be), many areas where the docs can be improved. The docs will never be "finished", so - as well as documenting all the new features in each release, we're also keeping tabs on the many areas that can be improved.

    cory_munky - I appreciate the time you've taken to detail the specific pages you're having a problem with, and I'll try to get them improved as soon as possible.

    neonblitzer - My understanding from the current docs is that EditorGUIUtility.Load has two main features over Resources.Load

    1. Because it uses a separate folder, the resources referenced will not be included in your final build. Whereas if you used Resources.Load, those files (eg, editor inspector icons for custom tools) would unnecessarily be included in your final game build - because everything in the Resources folder is included in your build whether it's used or not. This means if you've made your own editor tool which needs to load assets like this, you can have it do so without those assets adding to your game's filesize.

    2. It also provides access to Unity's built-in editor resources, such as the icons used throughout the Unity Editor interface. (by name, although currently that page does not tell you what the names are!)

    I'll see what I can do about getting more info on this page too.
     
  4. wechat_os_Qy04HudZHoJnv61UM2gp54XhY

    wechat_os_Qy04HudZHoJnv61UM2gp54XhY

    Joined:
    May 25, 2020
    Posts:
    3
  5. wechat_os_Qy04HudZHoJnv61UM2gp54XhY

    wechat_os_Qy04HudZHoJnv61UM2gp54XhY

    Joined:
    May 25, 2020
    Posts:
    3
    why AssetDatabase.LoadAssetAtPath<Object>() function can't Load *.FBX file? thank you ! sorry i can only speak a little english
     
  6. wechat_os_Qy04HudZHoJnv61UM2gp54XhY

    wechat_os_Qy04HudZHoJnv61UM2gp54XhY

    Joined:
    May 25, 2020
    Posts:
    3
    but load FBX with animation (like *@animationName.FBX file) work fine.