Search Unity

how to access Resource folder on runtime/build[Solution found]

Discussion in 'Scripting' started by simonlvschal, Nov 19, 2018.

  1. simonlvschal

    simonlvschal

    Joined:
    Nov 17, 2015
    Posts:
    266
    so currently i ran into a problem with things not being created/loaded because of the possible wrong usage of methods.

    at the moment for windows based code i use

    Code (CSharp):
    1.  
    2. string[] folders = Directory.GetDirectories(Application.dataPath + "/" + "Resources/Areas/" + currentArea.areaName);
    3.  
    4.  
    this is to get all folders in a specific folder.

    but for some reason on runtime when building a project it does not load the data? can someone assist me?


    [Temporary Solution]
    Code (CSharp):
    1.  
    2. Resources.LoadAll<Area>("Areas/" + tempAreaName).Where(x => x.parentTown != null && x.parentTown.name == tempAreaName);
    simply said i want to find a way to count how many of a specific object existed in a folder. but this did not seem to work with Directory due to not having access to resources
     
    Last edited: Nov 20, 2018
  2. Reeii

    Reeii

    Joined:
    Feb 5, 2016
    Posts:
    91
  3. qkson

    qkson

    Joined:
    Jan 15, 2018
    Posts:
    77
    as @Reeii said, use Resources.Load and don't forget to actually put the thing into proper folder in Assets
     
  4. simonlvschal

    simonlvschal

    Joined:
    Nov 17, 2015
    Posts:
    266
    no that wont work to get folders. and also i found a different solution.
     
  5. IvarVanWijnen

    IvarVanWijnen

    Joined:
    Apr 10, 2018
    Posts:
    4
    I see you have the same problem as me.
    For the Editor it's no problem but when you build it is.

    I like to know as well how to get easy all the subfolders in the resource folder. (So no assets just the folder).
     
  6. Resources IS NOT a folder in build. It's a resource file and the path you added in the editor will be the index to the file you try to load. There is no command to get all the paths you have in the Resources and you really should use this VERY sparingly (in other words: you should not use it at all, usually).