Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by AbyssEnt · May 27, 2018 at 08:24 AM · coroutinesave dataiapwebrequestasync

Save data async (and wait for it) from a coroutine

Hello all, Hopefully someone can help me. I was previously using async functions to get/post data to our web servers which worked great, however the verson of Unity we are using (2018.1) does not support TLS 1.2. A beta version does, however we then run into a problem that Unity IAP is broken for that version, so i'm stuck having to revert lots of code calls back to use coroutines and UnityWebRequest functions.

At game start, we download various bits of data, assetbundles etc. I can get them downloading fine with UnityWebRequest in a coroutine, however I then need to be able to save this data to disk, async and wait for this to complete.

How can I do this from a Coroutine? Alternatively, i'd much prefer to use HttpWebRequest functions, as theyre async and I can control and return from those much better, so how could we implement a version of TLS 1.2 in our current Unity version?

Thanks for help in advance, Jack

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Legend_Bacon · May 30, 2018 at 04:14 PM

Hello there,

I'm not too sure about the specifics of your problem, but I hope this can help you. This is how I get a translation text from a database in an asynchronous manner.

• This is to call the Coroutine:

 StartCoroutine(GetTranslationCoroutine(value =>
             {
                 // The code in here only runs once the Coroutine is has returned something////////////
                 if (value.Key)
                     // Value seems to be valid, do something with 'value.Value'
                 else
                     UnityEngine.Debug.LogError("Could not retrieve translation for: " + translationKey);
                 /////////////////////////////////////////////////////////////////
 
             }, translationKey));




• And this is the Coroutine itself:

     public IEnumerator GetTranslationCoroutine(Action<KeyValuePair<bool, string>> value, string translationKey)
     {
         WWWForm form = new WWWForm();
         form.AddField("post_translation_key", translationKey);
 
         WWW www = new WWW("the url");
 
         while (!www.isDone)
         {
             // Processing...
             yield return null;
         }
 
         if (www.bytesDownloaded > 0)
         {
             //Here, perform checks to see if the returned data is valid
             if(!string.IsNullOrEmpty(www.text))
             {
 
                 //This returns a value to the callback. Note that the code after this line still gets executed.
                 value(new KeyValuePair<bool, string>(true, www.text));
             }
             else
             {
                 value(new KeyValuePair<bool, string>(false, "some error message: " + www.error));
             }
         }
         else
         {
             value(new KeyValuePair<bool, string>(false, "some error message: " + www.error));
         }
 
         yield return null;
     }



Hopefully this can give you a lead.

Cheers,

~LegendBacon

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 AbyssEnt · May 30, 2018 at 05:47 PM 0
Share

Is that async? I was under the impression coroutines are not async.

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

148 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How call async task in Unity 4 Answers

Load Scene in Background and Load When a Button is Clicked 0 Answers

Is true async scene loading possible? 0 Answers

Unity coroutine movement over time is not consistent/accurate? 1 Answer

Power up not working 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