Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

probem with yield return www

Discussion in 'Scripting' started by karllos, Aug 10, 2014.

  1. karllos

    karllos

    Joined:
    Sep 23, 2010
    Posts:
    9
    Need help with the c# code. problem is in yield return www. everything works great in unity editor and standalone exe file, but on android and webplayer it doesn't work. This code gets some json information from localhost and with "for" loop assigns json values to some variables. first yield return request; works great, but there is a problem on second yield return www;. In first yield i get names and scores and on second yield i get picture links. The links look like "graph.facebook.com/v2.1/816783911674988/picture/". If i change the code N["picture"].Value to something like this "http://www.something.com/images/somthing.jpg" everything works fine. i don't understand what i am doing wrong.

    Code (CSharp):
    1. IEnumerator GetData()
    2.         {
    3.             WWW request = new WWW("http://localhost/disp.php");      
    4.             yield return request;      
    5.             if (request.error == null || request.error == "")
    6.             {          
    7.                 var N = JSON.Parse(request.text);
    8.                 for (int i = 0; i <=9; i++)          
    9.                 {  
    10.                     if(N[i] != null)
    11.                     {
    12.                     Fname.text = N[i]["name"].Value;
    13.                     Fscore.text = N[i]["score"].Value;
    14.  
    15.                     WWW www = new WWW(N[i]["picture"].Value);
    16.                     yield return www;
    17.                     fpicture.mainTexture = www.texture;
    18.                     GameObject itemleft = NGUITools.AddChild(friendslistgrid,itemprefab);                              
    19.                     }
    20.                     friendslistgrid.GetComponent<UIGrid>().Reposition();
    21.                 }          
    22.             }
    Please halp.
     
  2. Fraconte

    Fraconte

    Joined:
    Dec 6, 2013
    Posts:
    327
    At first glance, the former seems more a folder than a picture (no .jpg).
    Can you print "N ["picture"].Value" and copy/paste it in a browser?
     
  3. karllos

    karllos

    Joined:
    Sep 23, 2010
    Posts:
    9
    In unity editor and standalone everything works. Yes, when i copy the N ["picture"].Value in browser i can see the picture.
     
  4. karllos

    karllos

    Joined:
    Sep 23, 2010
    Posts:
    9
    During coding in first stages when i was testing it was working on android, but somehow when i finish the code it didn't work at all. i changed something and now I've got this problem. I don't remember what changes I made. but i thing that problem is in yield return www; because on editor it needs some time to make list and on android it make it immediately.
     
  5. Fraconte

    Fraconte

    Joined:
    Dec 6, 2013
    Posts:
    327
    if you add this after the www yeld?
    Code (CSharp):
    1. if (!String.IsNullOrEmpty(www.error))
    2.             Debug.Log(www.error);
     
  6. karllos

    karllos

    Joined:
    Sep 23, 2010
    Posts:
    9
    conscole is empty
     
  7. Fraconte

    Fraconte

    Joined:
    Dec 6, 2013
    Posts:
    327
    Have you tested different Android phones/versions?
     
  8. karllos

    karllos

    Joined:
    Sep 23, 2010
    Posts:
    9
    On two android phones. same issue.
     
  9. Fraconte

    Fraconte

    Joined:
    Dec 6, 2013
    Posts:
    327
    I tryed in the webPlayer and end up with a failed download image "?" while in Editor works fine.
    I got this error in the webplayer log:

    Platform assembly: D:\Users\Fra\AppData\LocalLow\Unity\WebPlayer\player\Release3.x.x\Data\lib\CrossDomainPolicyParser.dll (this message is harmless)
    Failed downloading graph.facebook.com/v2.1/816783911674988/picture/

    I found a thread talking of similar issues working in Editor but not in webplayer:
    http://forum.unity3d.com/threads/crossdomain-problems.64133/
     
  10. Fraconte

    Fraconte

    Joined:
    Dec 6, 2013
    Posts:
    327
    Implications for use of the WWW class
    The Unity webplayer expects a http served policy file named crossdomain.xml to be available on the domain you want to access with the WWW class, (although this is not needed if it is the same domain that is hosting the unity3d file).

    http://docs.unity3d.com/Manual/SecuritySandbox.html
     
  11. Fraconte

    Fraconte

    Joined:
    Dec 6, 2013
    Posts:
    327
  12. karllos

    karllos

    Joined:
    Sep 23, 2010
    Posts:
    9