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

Potential bug - Resources.LoadAll<T>("")

Discussion in 'Scripting' started by JACLEMGO, Nov 11, 2021.

  1. JACLEMGO

    JACLEMGO

    Joined:
    May 30, 2013
    Posts:
    30
    When using Resources.LoadAll<T>("")

    1. Does Unity Load ALL resources of this type ONLY, or,
    2. Does unity load ALL resources, and then checks for the type.
    For example, if the type is an instance of a Scriptable object, will Unity only load Scriptables in the Resources folder(s), or all assets in Resources, and then check the Type?

    using dotPeek, it seems like it loads ALL assets, and then compares types:

    public static T[] LoadAll<T>(string path) where T : Object => Resources.ConvertObjects<T>(Resources.LoadAll(path, typeof (T)));

    public static extern Object[] LoadAll([NotNull("ArgumentNullException")] string path, [NotNull("ArgumentNullException")] System.Type systemTypeInstance);

    but cant peek further than that.
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,904
    I don't really see (from your post) what makes you think that, but you can test it further with memory profiling, just load up 1kb SO and 10 megs others from a folder and you will notice if the memory deplete noticeably, I think. Also don't forget, Resources always loads up the entire file-index about all files in all Resources.
    And the mandatory: shouldn't use Resources.
     
    JACLEMGO likes this.
  3. JACLEMGO

    JACLEMGO

    Joined:
    May 30, 2013
    Posts:
    30
    Thanks mate. From the Profiler, it seems like everything in Resources is loaded, not just of that type.