• 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
Question by ks13 · Dec 14, 2011 at 09:32 AM · coroutineassetbundlewwwyield

Yield Problems

Helo, i'm trying to use WWW to get an assetbundle on a local server. The problem is when i try to use "yield" to get the asset i get the following error message :

 Failed to load asset bundle
 UnityEngine.WWW:get_assetBundle()

Here's the code :

 //Default dimensions for the text area
     public int defWidth = 500;
     public int defHeight = 25;
     //Object on which the material will be applied
     public GameObject obj;
     //Used to check if the url was changed | avoid reloading the file
     private string lastUrl = "Enter the adress";
     //Te actual variable containing the url of the file
     private string url = "Enter the adress";
     //The variable containing the adress of WWW method
     private WWW wwwTest = null;
     //The variable containing the adress of the material
     private Material mat;
 
 private void LoadPart(string link)
     {
         if (lastUrl != link)
         {
             StartCoroutine(GetAsset(link));
             if (wwwTest.error != null)
                 Debug.Log(wwwTest.error);
         }
     }
 
     private IEnumerator GetAsset(string link)
     {
         AssetBundle ab;
         wwwTest = new WWW(link);
         yield return wwwTest;
         ab = wwwTest.assetBundle;
     }
 
     void OnGUI()
     {
         int lastYPos = 0;
         int textAreaHeight = defHeight;
         int textAreaWidth = defWidth;
         int buttonWidth = 50;
         int buttonHeight = 20;
         url = GUI.TextField(new Rect((Screen.width - textAreaWidth) / 2, lastYPos, textAreaWidth, textAreaHeight), url);
         lastYPos += textAreaHeight;
         if (GUI.Button(new Rect((Screen.width - buttonWidth) / 2, lastYPos, buttonWidth, buttonHeight), "Load"))
             LoadPart(url);
         lastYPos += buttonHeight;
     }

This is only a testing code to see how assetbundles work, but so far i failed to understand how to use it with or without coroutines.

Edit : this error is the same i had when i wrote the code without a coroutine. I don't uderstand why it fails to load, when i try to import the assetbundle from the editor it works fine. In there is only a material called "Ananas" with texture of ananas skin.

Comment

People who like this

0 Show 0
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
Best Answer

Answer by ks13 · Dec 14, 2011 at 01:47 PM

Wow, i don't want to believe this, but it seems some people don't even read the code before answering. As it turns out, the yield wasn't the problem. I checked every part i yielded and everything went fine, even the size of the file loaded was the same. The only thing was the failing of loading. After much checking, it seems i was building my bundles wrong, and that's why WWW couldn't load them.
Just saying in case someone else has the same problem, if :
- isDone = true
- error = null
- size = size of the bundle
then the problem is most likely the bundle itself.

Comment
Chris D
BeHappy

People who like this

2 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 BeHappy · Oct 17, 2012 at 11:11 AM 0
Share

Thanks a lot ks13...ur answer helped a lot...

avatar image

Answer by Eric5h5 · Dec 14, 2011 at 09:53 AM

You're not yielding on the GetAsset coroutine, as the error says.

Comment

People who like this

0 Show 5 · 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 ks13 · Dec 14, 2011 at 10:04 AM 0
Share

Uh, ok, can you give a little more details? Because from the examples i've seen in Unity Scripting Manual or codes shown in here, it's the way to do it. Which is obviously wrong seeing the error, but i don't see how else to do it.

Edit : ok, forgot to change the name of the WWW variable to the new name, updated the post with the new error.

avatar image Eric5h5 · Dec 14, 2011 at 10:14 AM 0
Share

Might want to take another look at the docs...yield return new StartCoroutine... Otherwise it just returns immediately, hence the error.

avatar image ks13 · Dec 14, 2011 at 10:28 AM 0
Share

StartCoroutine only starts the coroutine so it's normal it returns immediately, but the coroutine started continues executing, that's why i used global variables and yield inside the started coroutine. Unless i misunderstood something, i think that's the way to use it.
The way i coded it, it should start a coroutine, GetAsset, that's going to download and load the wanted asset, while downloading with WWW, i pause GetAsset with yield, then load the asset. That's the intended behaviour. Similar to this example. Am i wrong?

avatar image Eric5h5 · Dec 14, 2011 at 10:34 AM 0
Share

Yes, that's wrong, please read what I wrote again; also look at the second example on that page, not the first.

avatar image ks13 · Dec 14, 2011 at 10:40 AM 0
Share

Ok, sorry but you lost me here. I've looked at the second example and don't uderstand what you're hinting at. Unless you're saying i have to use WaitForSeconds...

Edit : I forgot to mention this but, this code works when i try to load and diplay a jpg image. This is why i think the loading should work, and the code is properly structured.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

yield on a www never completes 10 Answers

loading asset bundle function 1 Answer

Loading files via WWW class and Unity hangs for a few seconds if I use coroutines. If I don't, it works perfectly. What is going on? 1 Answer

Yielding with WWW in Editor 9 Answers

How to imitate yield functionality like WWW class 0 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