Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resources.Load returns null in a build, but works in the editor

Discussion in 'Editor & General Support' started by nikita-g, Jun 6, 2012.

  1. nikita-g

    nikita-g

    Joined:
    Jun 6, 2012
    Posts:
    1
    Hello Everyone,

    I recently updated my project with a new high res art and I am experiencing a problem now. Resources.Load returns null in a build, but works in editor. I tried builds for Windows and Mac that were built using 3.4.2 and 3.5.2.

    When I remove half of art files from Resources folder builds are working perfectly. Also I reimported all assets a couple of times and it didn't help.

    It would be great to get some direction or hear your thoughts about this problem. Any help will be appreciated.

    For example I have a test script that executes perfectly in the editor, but doesn't work in a build.

    if (Resources.Load ("Images") != null){
    Debug.Log("Images.xml is loaded! "); // executes in the editor
    }else{
    Debug.LogError("Can't find Images.xml! "); // executes in a build
    }

    Thank you very much,
    Nikita
     
    jpthek9 likes this.
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Is there any reference pointing to your resource? All resources are deleted from the builds, unless they are somehow referenced. As far as I know, objects from any scene of the build, objects that are referenced by those are part of the build only. You may try to add a dummy game object with a script that simply exists to have the references to those files you are trying to load. Hope it helps.
     
  3. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,660
    Assets in the Resources folder are exempt from that; they're all included in the build regardless of whether you're using them or not.
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Not sure if .xml is an accepted and supported format in which case Unity won't include it in builds either.

    .txt (and .xml.txt) is recognized as text asset and could be used as a text asset though
     
  5. Ali-Nagori

    Ali-Nagori

    Joined:
    Apr 9, 2010
    Posts:
    151
    same Problem Here , i doubt it to be a bug .

    the image just sum it up , previews both editor and build -> [High Graphic settings]

     
    Last edited: Jul 2, 2012
  6. Ali-Nagori

    Ali-Nagori

    Joined:
    Apr 9, 2010
    Posts:
    151
    i had to submit this followup because the problem was from my custom shaders and not the Resources.load



    @nickmarty

    try type casting
    [Resources.Load ("Images") as TextAsset]
     
  7. gregzo

    gregzo

    Joined:
    Dec 17, 2011
    Posts:
    795
    Just had the same problem : Resources.LoadAll in Awake fails to load if there's too much data(but works in the editor). In my case, 49 100k files and 49 1mb files : only the former was loaded. The latter did return an Object[], which was cast to the right type: no errors, nothing amiss except missing data...

    Shifting Load from Awake to Start and yielding between the two calls solved the problem for me.

    Will file a bug report.

    G
     
  8. nikolay_i

    nikolay_i

    Joined:
    Jan 5, 2020
    Posts:
    13
    The same problem in 2021, our CI doesn't work because we try to keep configurations in scriptable objects in resources folder