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 omatase · Feb 07, 2015 at 04:41 PM · wwwyieldstartcoroutine

yield return on WWW never coming back?

I'm making a web hit with the WWW class. Something I have done a dozen times in other places but for some reason, although the hit to the server hits and comes back, the Unity client never picks the response up. I'm wondering if it's something quirky about WWW that I just haven't experienced before. I did some searching but everyone else having this problem is just because they didn't use StartCoroutine when initiating the communication. This isn't my problem.

Code calling method that yield returns the WWW object.

 StartCoroutine(_director.ProcessInstant(new Battleschool.Common.Entities.Contract.InstantDetail { AbilityId = _ability.AbilityId, GameId = BattleStatics.Instance.GameId, RoundIndex = (short)BattleStatics.Instance.RoundIndex, SourceId = _sourceCharacterData.CharacterId, TargetId = _targetCharacters.First().CharacterId }));

The method making the hit itself.

 internal IEnumerator ProcessInstant(InstantDetail details)
 {
     WWW www = new WWW(DirectorHelper.GetUri("Battle/ProcessInstant"), DirectorHelper.PrepareBody<InstantDetail>(details), DirectorHelper.GetHeaders());
 
     yield return www;
 
     // execution never makes it to this point
     if (OnProcessInstantComplete != null)
     {
         OnProcessInstantComplete(this, DirectorHelper.DeserializeAsBase64FromNetwork<IInstantResponse>(www.text));
     }
 }

Here's the response coming back from the server as captured by Fiddler.

 HTTP/1.1 200 OK
 Server: ASP.NET Development Server/10.0.0.0
 Date: Sat, 07 Feb 2015 16:34:20 GMT
 X-AspNet-Version: 4.0.30319
 Cache-Control: no-cache
 Pragma: no-cache
 Expires: -1
 Content-Type: application/json; charset=utf-8
 Content-Length: 686
 Connection: Close
 
 "AAEAAAD/////AQAAAAAAAAAMAgAAAExCYXR0bGVzY2hvb2wuQ29udHJhY3QsIFZlcnNpb249MS4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsBQEAAAA0QmF0dGxlc2Nob29sLkNvbW1vbi5FbnRpdGllcy5Db250cmFjdC5EaXZpbmVSZXNwb25zZQcAAAAcPFRvdGFsSGVhbHRoPmtfX0JhY2tpbmdGaWVsZB48Q3VycmVudEhlYWx0aD5rX19CYWNraW5nRmllbGQaPFRvdGFsTWFuYT5rX19CYWNraW5nRmllbGQcPEN1cnJlbnRNYW5hPmtfX0JhY2tpbmdGaWVsZBY8TGV2ZWw+a19fQmFja2luZ0ZpZWxkFjxDbGFzcz5rX19CYWNraW5nRmllbGQUPEtleT5rX19CYWNraW5nRmllbGQAAAAAAAEBCAgICAgCAAAAWgAAAFoAAAAyAAAAMgAAAAEAAAAGAwAAAAlEaXNtaXNzZXIGBAAAAAZEaXZpbmULAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="

Appreciate any insights into this.

-=-=-UPDATE-=-=-

Incidentally, I moved to a completely synchronous approach by removing the StartCoroutine and changing the method making the hit to the below and it works fine. Of course, this can't serve as a solution, but thought it was interesting.

 internal void ProcessInstant(InstantDetail details)
 {
     WWW www = new WWW(DirectorHelper.GetUri("Battle/ProcessInstant"), DirectorHelper.PrepareBody<InstantDetail>(details), DirectorHelper.GetHeaders());
 
     while (!www.isDone) { }
 
     //yield return www;
 
     if (OnProcessInstantComplete != null)
     {
         OnProcessInstantComplete(this, DirectorHelper.DeserializeAsBase64FromNetwork<IInstantResponse>(www.text));
     }
 }
Comment
Add comment · Show 4
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 Graham-Dunnett ♦♦ · Feb 07, 2015 at 06:12 PM 0
Share

If I had this problem, I'd start checking that the content-length is correct. The body is utf8, so it's possible (but unlikely) that the number of bytes transferred differs from the content-length, so the WWW class is waiting for the correct number of bytes. Doesn't immediately explain why the sync version works. Sometimes the while loop consumes so much cpu that the WWW times out. You don't check to see if you have an error...

avatar image omatase · Feb 07, 2015 at 06:59 PM 0
Share

Thanks @Graham Dunnett. All of the data is serialized to a byte[] then Base64 encoded so it's not possible that the content length will be anything different than the length of the raw string in the body of the response. I have checked that the length of the string also matches the Content-Length header. You're right, the code isn't looking for an error and handling it, I will add that as I finish this up. That also can't be related to the problem unfortunately since checking for an error still requires that I get call execution back.

avatar image Bonfire-Boy · Feb 07, 2015 at 07:08 PM 1
Share

Only other thing that springs to $$anonymous$$d is something else interrupting while the CR has yielded. Like if the component it's on has been destroyed. Sounds like you're savvy enough to have thought of that but seemed worth mentioning as it's something that would impact on the CR method but not the while(!isDone) method.

avatar image omatase · Feb 08, 2015 at 03:47 AM 0
Share

@Bonfire Boy, oh crap. Guess I'm not that savvy. You're so right. That's what it is. Thanks for the help!

0 Replies

· Add your reply
  • Sort: 

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

20 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

Related Questions

Wait for file download 1 Answer

How to imitate yield functionality like WWW class 0 Answers

Yield www within Gui Update() 0 Answers

StartCoroutine important for using yield? 1 Answer

Load external mp3 File without streaming 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