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 DazZzL · Oct 16, 2016 at 04:56 PM · coroutineyield

Problem with coroutine / yield

Hello,

Im using a piece of SQL within PHP to populate a popuplist.

PHP is really simple, just

 <?php
 $con = mysqli_connect('localhost','root','xxxxx','xxxxx') or ("#Cannot connect!"  . mysqli_error());
 if (!$con)
     echo('#Could not connect: ' . mysqli_error());
     
 $result = mysqli_query($con,"SELECT * from location");
 while ($row = mysqli_fetch_array($result))
         echo $row['LocationID']   . ":" 
            . $row['City']   . ":" 
            . $row['Description'] . "\n";
 mysqli_close($con);
 ?>

Wamp server is running and when I open the php in a browser it echoes as expected.

Im trying to use the popuplist in 2 different scenes. It works in one scene... but in the other it seems that the code 'halts' at the yield command.

The scriptcode is;

 using UnityEngine;
 using System.Collections;
 
 public class GetAllLocations : MonoBehaviour 
 {
     public void Start() {
         WWWForm form = new WWWForm ();
         form.AddField ("name", "");
         WWW w = new WWW ("http://localhost/EzonePlayer/getalllocations.php", form);
         StartCoroutine (getlocFunc (w));
     }
 
     IEnumerator getlocFunc(WWW w)
     {
         Debug.Log("Marker0");   
         yield return w;
         Debug.Log("Marker1");   
         if (w.error == null)
         {
                 Debug.Log("Marker2");
                 //Removed working code here to populate popuplist, not relevant for problem
         }
         else
         {
                 Debug.Log("Marker3");
                 //Removed working code here, not relevant for problem
   
         }
     }

}

In the working scene debug Marker0, 1 and 2 will show. In the not working scene only Marker0 shows.

I really can't figure out why the code works in one scene and doesnt work in the other scene. Anybody has any ideas what could be the problem?

I already tried renaming the coroutine to another name than in the other scene,

Thanks a lot in advance =)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Kyle_WG · Mar 16, 2017 at 02:27 PM

Try putting the WWW object as a member variable.

      using UnityEngine;
      using System.Collections;
 
      public class GetAllLocations : MonoBehaviour 
      {
          WWW w = null;
          public void Start() {
              WWWForm form = new WWWForm ();
              form.AddField ("name", "");
              w = new WWW ("http://localhost/EzonePlayer/getalllocations.php", form);
              StartCoroutine (getlocFunc ());
          }
      
          IEnumerator getlocFunc()
          {
              Debug.Log("Marker0");   
              yield return w;
              Debug.Log("Marker1");   
              if (string.IsNullOrEmpty(w.error))
              {
                      // Success
                      Debug.Log("Marker2");
                      //Removed working code here to populate popuplist, not relevant for problem
              }
              else
              {
                    // Fail
                      Debug.Log("Marker3");
                      //Removed working code here, not relevant for problem
        
              }
              w.Dispose();
             w = null;
          }

Had a few problems myself not explictly holding the refernce to that class and not disposing when finished either.

Everything else seems fine though. Added a more explicit check for w.error too as I think error can sometimes be an empty string rather than null.

Comment
Add comment · 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
0

Answer by alankemp · Mar 16, 2017 at 02:40 PM

Are you destroying the game object that your GetAllLocations script is attached to?

Coroutines are owned by the game object that starts them, if the game object is destroyed the coroutine will stop.

Comment
Add comment · 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

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

82 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

Related Questions

Coroutine doesn't continue after yield another coroutine 0 Answers

Coroutine: delay transform rotation but start transform movement immediately 2 Answers

Designing a dialogbox that displays message, returns a custom object and waits for user response 0 Answers

Coroutines Madness (); 1 Answer

Invoke method is not called 2 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