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 JedBeryll · May 16, 2015 at 06:59 PM · resources.loadresources.loadall

Resources.Load / LoadAll

Hi! Load doesn't work like LoadAll?

 GameObject loadedAsset = Resources.Load<GameObject>("Prefabs/Ships/" + "shipname");
 
 GameObject[] loadedAssets = Resources.LoadAll<GameObject>("Prefabs/Ships/");

If i print the results LoadAll works but Load returns null. I'm sure i have the path and file name correctly and i have tried adding .prefab after the ship name. Anyone know if there is a way to make it work? Full path is: E:/Game/Assets/Resources/Prefabs/Ships/

Comment
Add comment · Show 8
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 maccabbe · May 16, 2015 at 08:14 PM 1
Share

The code provided does not compile since Resources.LoadAll has a return type of GameObject[].

avatar image JedBeryll · May 16, 2015 at 08:52 PM 0
Share

Sorry that was just a mistake. Corrected the original post.

avatar image $$anonymous$$ · May 16, 2015 at 09:03 PM 0
Share

Try to load your Prefab with this method:

 public static T Load<T>(string path) where T : Object {
         T thing = (T) Resources.Load(path);
         if (thing == null)
             Debug.LogError("Couldn't load resource '"+typeof(T)+"' with path '"+path+"'");
         return thing;
     }
avatar image JedBeryll · May 16, 2015 at 09:20 PM 0
Share

Pasted your code and used this to call the method:

 GameObject loadedAsset = Load<GameObject>(Application.dataPath + "/Resources/Prefabs/Ships/" + sf.GetSelected() + ".prefab");

Gives me this error: Couldn't load resource 'UnityEngine.GameObject' with path E:/Game/Assets/Resources/Prefabs/Ships/ship1.prefab

avatar image $$anonymous$$ · May 17, 2015 at 12:29 PM 1
Share

Just got a similar setup to work on my computer.

What I did:

 var obj = Resources.Load("Prefabs/Ships/shipname");
 Debug.Log(obj);

Can you try this code?

Note: I didn't need the ".prefab" to load my prefab.

Note 2: $$anonymous$$ake sure your folder is called "Resources" and not "Resource"

Show more comments

2 Replies

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

Answer by Imploding_Dragons · May 17, 2015 at 03:20 PM

Just made a prefab with some components and change some data and put it into the Resources folder.

and then loaded like this;

 GameObject testobject = Resources.Load("Test") as GameObject;
 GameObject.Instantiate(testobject);

Worked fine no problems created the asset into the scene with all the data + components.

Final Notes:

Make sure you have the Case and spelling correct. eg Apple and AppLe is different.

Comment
Add comment · Show 3 · 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 JedBeryll · May 17, 2015 at 04:27 PM 0
Share

Ok so the problem was that i used a subfolder of a Resources folder. Apparently the file needs to be specifically in Resources. Thank you all for the help!

avatar image Imploding_Dragons · May 17, 2015 at 04:39 PM 1
Share

That Shouldn't be a problem, I made a folder test and a prefab test inside it.

 GameObject TempObject = Resources.Load("Test/Test") as GameObject;


and it loaded fine, I just tested it case doesn't seem to matter. Perhaps that particular prefab was glitched and moving it fixed it.

avatar image JedBeryll · May 17, 2015 at 04:52 PM 0
Share

I replaced the prefab now it works even in subfolder. Guess it was a glitch then. Thanks!

avatar image
0

Answer by Baste · May 16, 2015 at 09:18 PM

You need to include the extension of the things you are loading. If it's a prefab, the extension is ".prefab", so you'd have to do:

 GameObject loadedAsset = Resources.Load<GameObject>("Prefabs/Ships/" + shipname + ".prefab");
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 JedBeryll · May 16, 2015 at 09:29 PM 0
Share

Tried that too, didn't work but thanks for the tip.

avatar image Bunny83 · May 17, 2015 at 11:56 AM 1
Share

@Baste
Resources.Load requires you to omit the extension. So you when you add an extension it certainly won't work. His original code should work as long as the name of his prefab is correct.

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

22 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

Related Questions

ridiculous load time using Resources.Load() on android build 0 Answers

Best method for memory usage. 0 Answers

Loading Resources in a Native Plugin 0 Answers

Instanciate gameobject from Resources subfolder 1 Answer

Interact with objects from Resources.Load 3 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