Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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:
    580
    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,494
    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:
    580
    Ok thanks, so what would I pass the LoadAll method? I tried, "", but no luck.
     
  4. keenanwoodall

    keenanwoodall

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

    KelsoMRK

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

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    580
    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!!!!!!!!
     
unityunity