Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

WWW failing

Discussion in 'Windows Mixed Reality' started by mavasher, Jul 21, 2016.

  1. mavasher

    mavasher

    Joined:
    Nov 20, 2013
    Posts:
    13
    I'm having a great deal of difficulty getting the WWW function to work correctly on the Hololens. My code works perfectly on my development PC. No joy when run on the Hololens. I've tried various iterations to try to find the break point but I'm getting answers that do not make a lot of sense.

    Here's my code:
    Code (CSharp):
    1. public class WebCam5 : MonoBehaviour
    2. {
    3.     public string url = "";
    4.     private float timeout = 0.2f;
    5.     private Renderer mainRenderer;
    6.     public Console console;
    7.     public Console console2;
    8.     private int i = 0;
    9.     private WWW oldwww;
    10.  
    11.     // Use this for initialization
    12.     void Start()
    13.     {
    14.         mainRenderer = GetComponent<Renderer>();
    15.         StartCoroutine(UpdateCam());
    16.     }
    17.  
    18.     IEnumerator UpdateCam()
    19.     {
    20.        
    21.         console.Message = "Co-routine started-";
    22.         while (true)
    23.         {
    24.             WWW www = new WWW(url);
    25.             yield return www;
    26.             FetchFrame(www);
    27.             if (oldwww == www)
    28.             {
    29.                 console.Message = "Old WWW active";
    30.             }
    31.             else {
    32.                 console.Message = "Unequal.";  //Both PC and Hololens report "Unequal."
    33.             }
    34.             i++;
    35.  
    36.             console2.Message = i.ToString() + "bytes = "+www.bytesDownloaded.ToString();  //Correctly Iterates on both PC and Hololens.
    37.             oldwww = www;
    38.             yield return null;
    39.         }
    40.     }
    41.     void FetchFrame(WWW www) {
    42.  
    43.        
    44.         console.Message = "www completed.+" + www.bytesDownloaded.ToString();
    45.         Texture oldTexture = mainRenderer.material.mainTexture;
    46.         console.Message = "pulled old texture.";
    47.         Texture newTexture = www.textureNonReadable;
    48.         console.Message = "created blank texture.";
    49.         mainRenderer.material.mainTexture = newTexture;
    50.         console.Message = "newTexture applied.";
    51.         Destroy(oldTexture);
    52.         console.Message = "Old texture destroyed.";  //Both Hololens and PC show this message.
    53.  
    54.     }
    55. }
    56.  
    The behavior on the Hololens is that the Hololens is successful in pulling one frame of an mpeg video feed (I have a server set up which serves up textures in .jpg format") However it only make one requests to the server while on the PC, the script continually requests the most update frame and it appears as a video feed.

    Any idea why this peculiar behavior on the Hololens but everything works great on the PC?
     
    Liut2018 likes this.
  2. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    557
    Hello,

    Can you update to the latest 5.4.0f1-HTP build and try again please? Also, can you let us know the results.

    Thank you,
    Wesley
     
  3. mavasher

    mavasher

    Joined:
    Nov 20, 2013
    Posts:
    13
    Thanks for the reply.

    Just Installed 5.4.0f1-HTP and upgraded the project. Builds fine on the Hololens but the behavior is the same. I get one image from the WWW call but it then doesn't make another request. Again, everything works perfectly on the development PC.

    I have also re-written the code to avoid use of the coroutine thinking that perhaps was this issue, now I use Update() to check for WWW to be complete before requesting the next frame - this works great on the development PC, in fact I got a speed boost out of it, but this still fails on the Hololens.

    It appears to me that the Hololens is populating the new WWW() object with data already obtained instead of requesting new data from the network. On my server, I register only one request from the Hololens when the program is started, but on the PC the server registers multiple requests, multiple frames. The Hololens confirms that the new WWW() object is distinct from the old WWW() object, i.e. the old frame. But it appears to be populated with the same data -, i.e. the texture is the old texture and the "bytes received" never changes on the Hololens while on the PC this value is variable depending on the content of each texture frame. I have tried running Dispose on the www but this doesn't help.

    It appears that the Hololens is caching the old data instead of making a new request.
     
  4. ScottF

    ScottF

    Director of Development, Mobile Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    91
    @mavasher when you say it works on Development PC do you mean you it works on UWP desktop or works in the editor? This will help us narrow down the problem.

    Thanks
     
  5. mavasher

    mavasher

    Joined:
    Nov 20, 2013
    Posts:
    13
    It works fine in the Editor. I haven't tried to build it to a UWP - just in the editor.

    But, over the weekend, I was able to get it to work. What I found was that using WebRequest instead of WWW solved my problem.

    https://docs.unity3d.com/Manual/UnityWebRequest.html

    WWW seems to have a bug when deployed to the Hololens. I would provide a sample project but the project is essentially the above code attached to a quad in front of the camera.

    In any case- using WebRequest instead of WWW works great- the behavior is exactly the same in the Editor and on the device and works as needed.
     
  6. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    557
    Did you buy chance have the internet capabilities on in the player Settings?

    upload_2016-8-1_10-30-43.png

    sanity check
     
  7. mavasher

    mavasher

    Joined:
    Nov 20, 2013
    Posts:
    13
    Thanks for the reply. Yes, I did have all of the appropriate functions checked off in Unity. I wish it were that easy.

    I did notice however that I had to additionally check off these capabilities in VS in the Package.appxmanifest independently but this also didn't fix the WWW error.

    For my purposes UnityWebRequest is working great. Is WWW() being phased out?
     
  8. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    557
    I don't believe WWW is being phased, I will check with the team to see.
     
  9. blolson

    blolson

    Joined:
    Oct 6, 2015
    Posts:
    1
    Just to satiate anyone reading this thread and feeling like they hit a dead-end. I too was having issues with www on build 5.4.0f3-HTP and the issue eventually resolved itself using a combination of...
    • Don't overwrite your Hololens build, just delete the Hololens/Visual Studio "App"/"Build" folder that you built from Unity and start clean. This has solved a lot of problems I've experienced.
    • Check "InternetClient" in the Player Settings' Capabilities section as Unity_Wesley describes above. This solved one of my issues.
    • Try connecting to http:// and not https:// URLs. It seems https connections are a problem with WindowsRT. This resolved the connection issue for me.
    Lastly, if you're looking for sample server connection code to try on Hololens and you've hit this thread, this person's code worked well as a jumping off point and compiled in the editor, on the emulator, and on the Hololens: http://forum.unity3d.com/threads/2-...erver-and-free-hosting-recommendation.144261/

    I hope this helps someone!
     
  10. dezartoine

    dezartoine

    Joined:
    Mar 27, 2019
    Posts:
    1
    OMG after tries and tries it finally works ! Deleting the files and building from scratch was what helped me. Thank you !!