Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. 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

[QUESTION] Resources.Load issue

Discussion in 'Scripting' started by Bloodsys, Jan 14, 2021.

  1. Bloodsys

    Bloodsys

    Joined:
    Oct 29, 2014
    Posts:
    5
    Hello!
    I have an external SDK with
    Code (CSharp):
    1. var settings = Resources.Load<SomeSettings>("SomeSettings");
    2. if (settings == null)
    3. {
    4. throw new Exception("Can't find settings file.");
    5. }
    At some collab I started getting this exception.
    There are some changes in my project,
    SDK wasnt changed,
    SomeSettings file still exist and everything still works in the Editor.


    What could happen?
    What is the metodology of finding the solution in this case?
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    9,866
    Resources.Load looks for something in a Resources folder, within the Assets folder. The first thing I'd check is that the something it is looking for is actually in a Resources folder.
     
    Bloodsys likes this.
  3. Bloodsys

    Bloodsys

    Joined:
    Oct 29, 2014
    Posts:
    5
    Yes, resources foulder still contains the SomeSettings file.
    Also, I think there would be some errors in Editor if the file doesn't exist. And, as I mentioned before, there isn't any.
     
  4. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    521
    There are several things you should keep an eye out for. First of all any resources folder anywhere in your project will form a unified / merged virtual file system. So be careful with the naming of assets in resources folders because if you have a "SomeSettings" asset in
    /Assets/Resources/SomeSettings
    and another one over here:
    /Assets/SomeFolder/MySDK/Resources/SomeSettings
    , they will have the same name within the resources database. So make sure you have clear and unique names for your resources assets.

    Next thing is, just because there's an asset file with that name, does not necessarily mean it's the right asset. Keep in mind that ScriptableObject assets do have / need a reference to the actual class that it represents. Loosing the meta file of the scriptable object could cause a break in this reference. So there are a lot things that could have gone wrong due to some careless handling of the files.

    Can you post the script file of that settings file and maybe the content of the asset file (which should be yaml text)? Also the content of the meta file of the scriptable object class may also be useful. Though it's difficult to do a diagnosis of such issues through forum communication.

    Another thing you can check is if you have more than one of those "SomeSettings" classes, maybe in different namespaces? Serialized classes can cause issues if they have evil twins somewhere.
     
    Bloodsys likes this.
unityunity