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 grigdog · Aug 06, 2013 at 01:11 AM · yielddatadelegateweb services

Trouble Getting External Data Using WWW

Trying to use WWW to pull data from my webservice and I originally got an error saying "WWW is not ready downloading yet".

So, I figure I have to use "yield return www;", which led to me to using a delegate method. Now I am getting error: "NullReferenceException UnityEngine.MonoBehaviour.StartCoroutine (IEnumerator routine)".

I'm an experience .net C# developer, but this is seriously giving me trouble. What is the best way to go about something like this? Thanks!

In my ItemCatelog class:

 private void RequestItemCatelog()
 {
     data.GetItemCatelog(RecieveItemCatelog);
 }
 
 private void RecieveItemCatelog(CatelogItem[] items)
 {
     Debug.Log(items[0].ItemName);
 }

and in my datahelper class:

     public delegate void GetItemCatelogReceiver(CatelogItem[] items);
     public void GetItemCatelog(GetItemCatelogReceiver _GetItemCatelogReceiver)
     {
         StartCoroutine(GetItemCatelogResponse(_GetItemCatelogReceiver));
     }
     
     IEnumerator GetItemCatelogResponse(GetItemCatelogReceiver _GetItemCatelogReceiver)
     {
         WWW www = new WWW(url);
         Debug.Log(www.text);
         yield return www;    
         
         CatelogItem[] items = JsonMapper.ToObject<CatelogItem[]>(www.text);
         Debug.Log(www.text);
         _GetItemCatelogReceiver(items);
     }
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

4 Replies

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

Answer by Adamcbrz · Aug 06, 2013 at 03:49 AM

I had a problem when i copied your script because of requesting www.text before yielding to www. Here is the test I did with success and excluding the json list.

 using UnityEngine;
 using System.Collections;
 
 public class WWWTest : MonoBehaviour 
 {
     public delegate void GetItemCatelogReceiver(string text);
     void Start()
     {
          GetItemCatelog(RecieveItemCatelog);
     }
     
     void GetItemCatelog(GetItemCatelogReceiver _GetItemCatelogReceiver)
     {
        StartCoroutine("GetItemCatelogResponse", _GetItemCatelogReceiver);
     }
  
     IEnumerator GetItemCatelogResponse(GetItemCatelogReceiver _GetItemCatelogReceiver)
     {
        WWW www = new WWW("http://www.google.com");
        yield return www; 
  
        _GetItemCatelogReceiver(www.text);
     }
     
     private void RecieveItemCatelog(string text)
     {
         Debug.Log(text);
     }
 
 }
 
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 ei1 · May 17, 2016 at 03:42 AM 0
Share

Unity crashes everytime it reaches "yield return www". Unity 5.3.4

avatar image
1

Answer by foxvalleysoccer · Jul 09, 2015 at 03:32 PM

I got it working!

 void Awake()
     {
         isFirstRound = true;
 
         WWW result = GET("http://dev.wisc-online.com/Prototypes/muscle_structure.json");
 } 
 
 
 public WWW GET(string url)
     {
         WWW www = new WWW(url);
 
         StartCoroutine(WaitForWWW(www));
         //do nothing untill json is loaded 
         while (!www.isDone) {  }
 
         if (www.error == null || www.error == "")
         {
             gameData = convertFromJSONToMyClass(www.text);
             Debug.Log("gameData = " + gameData);
         }
         else
         {
             Debug.Log("WWW error: " + www.error);
         }
 
         return www;
     }
     IEnumerator WaitForWWW(WWW www)
     {
         yield return www;
     }
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
0

Answer by grigdog · Aug 06, 2013 at 04:44 AM

The problem was my ItemCatelog class was instantiating the DataHelper class with new(). Old .net habits die hard.

"yield return www" I had put in place to reproduce the "WWW is not ready downloading yet" error and accidently made it into the snippet.

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
0
Wiki

Answer by David-Hernan · May 14, 2015 at 06:55 PM

In my case, my game must wait for the web results before continuing, there is nothing to do while the results arrive, so I programmed it to wait until WWW is ready downloading.

 using UnityEngine;
 using System.Collections;
 
 public class Principal : MonoBehaviour
 {
     // This could be one of many methods which require data from web.
     public void Browse () 
     {
         // Make a call to the "GET" method providing the url.
         WWW result = GET("https://www.google.com.mx/search?q=UnityException%3A+WWW+is+not+ready+downloading+yet&oq=UnityException%3A+WWW+is+not+ready+downloading+yet&aqs=chrome..69i57j69i58.349j0j9&sourceid=chrome&es_sm=93&ie=UTF-8#safe=off&q=UnityException:+WWW+is+not+ready+downloading+yet");
 
         // Show the output.
         Debug.Log(result.text);
     }
 
     // The "GET" method is apart because it could be called from many methods.
     public WWW GET (string url)
     {
         // Create the WWW object and provide the url of this web request.
         WWW www = new WWW (url);
 
         // Run the web call in the background.
         StartCoroutine (WaitForRequest (www));
 
         // Do nothing until the response is complete.
         while (!www.isDone) {}
 
         // Deliver the result to the method that called this one.
         return www;
     }
 
     // Run the web call and deliver the result as it is arriving.
     private IEnumerator WaitForRequest (WWW www)
     {
         yield return www;
     }
 }
 
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

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

18 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

Related Questions

Yield to wait for delegate call 1 Answer

How To Create Coroutine Delegates? 1 Answer

Gameobject can not save variable attached to it ? 1 Answer

Syncing variables between two objects of same script 1 Answer

yield troubles. function needs to finish before continuing 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