Search Unity

Having Trouble Getting An Array Of All Resources via Resources.LoadAll

Discussion in 'Scripting' started by keenanwoodall, Jun 3, 2015.

  1. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    598
    I'm working on an in-game developer console and I want to list all object in the Resources directory. Whenever I call the method that is supposed to do that, I get returned an empty array or my method says that the resources folder wan't found. I'm sure there's a simple fix, but I haven't been able to figure it out. Basically, I call this method. and whatever I return will be posted to the console. For the string that is passed to the LoadAll method, I've tried an empty string, "/Resources/", "Resources", and pretty much every other variation that I could think of. Oh, and yes my Resources folder does have a prefab in it; directly inside the Resources folder - "Resources/Example Resource".
    Code (csharp):
    1.  
    2. private static string ListResources(params string[] args)
    3. {
    4.     UnityEngine.Object[] objects = Resources.LoadAll("Resources/");
    5.     if(objects == null)
    6.         return "The resources folder was not found";
    7.     int i = 0;
    8.     string returnString = "";
    9.     foreach(UnityEngine.Object resourceObject in objects)
    10.     {
    11.         i++;
    12.         returnString += "-- " + i.ToString() + ".) " + resourceObject.name + "\n";
    13.     }
    14.     return returnString;
    15. }
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    The path is a relative path *inside* a Resources folder. So in your example it'd be looking for Resources/Resources
     
  3. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    598
    Ok thanks, so what would I pass the LoadAll method? I tried, "", but no luck.
     
  4. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    598
    Actually, no I tried "" again and it worked haha. Thanks for the help m9!
     
  5. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Have you tried "/"
     
  6. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    598
    Code (csharp):
    1.  
    2. UnityEngine.Object[] objects = Resources.LoadAll("");
    3.  
    This is my current code and it's working just fine. Idk what the problem was earlier.
     
  7. michael_unity988

    michael_unity988

    Joined:
    Aug 30, 2018
    Posts:
    9
    thxxxxxx u so much!!!!!!!!