Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DevMerlin · Sep 27, 2020 at 10:59 PM · loadscriptableobjectresources

Resources.Load is not working with an existing file in Resources?

I am attempting to load a created ScriptableObject. The file gets placed correctly, and exists in a folder under /Resources/, as it is supposed to.

However, when it is actually loaded via Resources.Load, it returns a Null - even though a System.IO.File.Exists says that the path is valid - and that the file is actually correct. This is what handles the file load. All of the correct variables show up in Inspector and looking at the file in a text editor:


 public void loadLevel(string fileName)
 {
     // Path - Valid: Assets/GameAssets/Resources/Levels 
     string filePath = fileDirectory + fileName;
 
     if (System.IO.File.Exists(filePath + ".asset")) // The file does exist, and has content;
     {
         // Scriptable Object //
         Level tempLvl = Resources.Load<Level>(filePath); // No ".asset" on actual name 
         // Returns Null!
     }
 }



Can anyone tell me what might be going on here? I did one final test - moving everything directly into Resources, but it returned the same result.



Here is a example of a file that I'm attempting to load - so it's not actually null:

alt text

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by SlowCircuit · Sep 27, 2020 at 11:15 PM

When using Resources.Load you don't specify the full path, you specify the path within the Resources folder. So your path should be "Levels + fileName" not "Assets/GameAssets/Resources/Levels + fileName". Also, you need to omit the file extension of .asset. Read more here: https://docs.unity3d.com/ScriptReference/Resources.Load.html

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DevMerlin · Sep 27, 2020 at 11:20 PM 0
Share

Hah, that was it! Although it was in the comments that I only added .asset for the file check, but the directory was the problem. Thank you for that note.

avatar image
1

Answer by Burn0815 · Apr 11, 2021 at 08:17 AM

Once I had the problem with Resources.Load in Unity 2019.4: existing prefabs could not be instantiated anymore (after I did a complete reimport of all assets). I solved this by renaming the "Resources" folder to something else - then renamed it back to "Resources". Suddenly everything worked as expected again. Hope this might help someone having the same troubles ;)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image rbaud · May 01 at 07:30 PM 0
Share

Burn0815, thank you for sharing this! I was seeing all of my Resources in game in the editor, but not in my build.

After reading your post, I did a combination of renaming the "Assets/Resources" folder to "Assets/ResourcesA" and then renaming it back to "Assets/Resources" and deleting the .meta file for the folder. One of both of those things together made the Resources appear in game.

Thanks again! Have a great one.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

144 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I make sure a resource is loaded or is instantiated? 2 Answers

Loading ScriptableObject when I open Unity 1 Answer

Resources.Load("sprite") returning nil 0 Answers

Resources.LoadAllOfType With ScriptableObjects? 1 Answer

Resources.Load wont read text file 6 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges