Anyone an expert on Unity Coroutines? I am working on a project in Unity that loads/saves from a MySQL database. I have code that loads a list of characters from the database and displays them in a GUI object. I am calling that with:
Code: Select all
StartCoroutine(getUserCharInfo());
Then in getUserCharInfo, I have it set up a form to pass the UserID to a PHP script to get the info and echo it out so I can read it back. This works fine, except that once in a while, Unity doesn't wait for the Coroutine to finish (if the db is slow to respond for some reason), so the list doesn't update like it should.
I have this code in my Coroutine:
Code: Select all
IEnumerator getUserCharInfo() {
WWWForm form = new WWWForm();
form.AddField("userid", userData.user.gUserID);
WWW charWWW = new WWW(getCharURL, form);
yield return charWWW;
getCharURL is the URL of my PHP script. Shouldn't the "yield return charWWW" wait until the PHP script is done before continuing? Or is there something else I need to do to make Unity wait on this?