Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Cleroth · Jul 22, 2013 at 01:25 PM · assetloadresourcesfolder

Subfolders with Resources.Load not working

It seems that using subfolders inside Resources no longer works with Resources.Load

Examples:

Works:

var ind = Instantiate(Resources.Load("Indicator", typeof(GameObject))) as GameObject;

Folder structure:

Resources
— Indicator.prefab

According to this and a few other sources, this should work, yet it doesn't:

var ind = Instantiate(Resources.Load("UI/Indicator", typeof(GameObject))) as GameObject;

Folder structure:

Resources
— UI
— — Indicator.prefab

The documentation says:

The path is relative to any Resources folder inside the Assets folder of your project, extensions must be omitted.

If it's relative, then it should be working.

The only other way I've found to be able to organize the assets is to put a "Resources" folder inside every asset category. This really doesn't seem ideal to me, and will most likely result in a mess:

var ind = Instantiate(Resources.Load("Indicator", typeof(GameObject))) as GameObject;

Folder structure:

Resources
— UI
— — Resources
— — — Indicator.prefab

Does Unity really not support subfolders inside Resources anymore? Or am I doing something wrong? I've been trying to wrap my head around something I must be doing wrong, but it's getting quite frustrating and I've found no reason for it not to work.

Additionally, I've tried posting this issue on the Unity Support forum, but everytime I click on Submit New Thread, it does nothing and takes me to the forum.

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

Answer by advancexz · Nov 11, 2016 at 08:33 AM

just for the record: if you have another resource with the same name (different extension) in the same folder the Resource.Load will always return NULL, just realized after hours of struggle with this. In my particular case:

transition_bar.png

transition_bar.prefab -> transition_bar_pfb.prefab

Comment
Add comment · 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
1

Answer by TonyLi · Jul 22, 2013 at 05:05 PM

Loading resources from subfolders works fine for me in Unity 3.5 and Unity 4.

What about trying to break down each step?

 Object o = Resources.Load("UI/Indicator");
 if (o == null) Debug.Log("Load failed");

 GameObject go = o as GameObject;
 if (go == null) Debug.Log("Loaded object isn't GameObject");

 GameObject ind = Instantiate(go) as GameObject;
 if (ind == null) Debug.Log("Couldn't instantiate");

I'm guessing that one of the first two Debug.Log lines will report, and you'll be able to narrow down the issue.

Comment
Add comment · Show 2 · 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 Cleroth · Jul 22, 2013 at 05:30 PM 0
Share

Which version of Unity 4 are you using? I just updated to 4.2 and it now works, with the same code. I'm guessing it was a bug in Unity 4.1.5f

avatar image TonyLi · Jul 22, 2013 at 06:32 PM 0
Share

Hmm, I'm using 4.1.5f. I didn't know 4.2 was out yet. I guess I'll update today. Anyway, I'm glad it's working now for you.

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

17 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

Related Questions

Loading in Sprites outside of unity? 1 Answer

Resources.Load renaming/moving resources. 0 Answers

Resources.Load problem 1 Answer

Resources.Load wont read text file 6 Answers

Loading Asset in Android using StreamingAssets and UnityWebRequest 1 Answer


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