• 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
Question by tayyab43 · Jan 28, 2015 at 06:58 PM · wwwdatabaseloginonline

yield return WWW.text not downloading???

Basically i'm doing a simple username and password script from a mysql database but when i get the data then it keeps giving me a strange error: UnityException:

 WWW is not ready downloading yet
 UnityEngine.WWW.get_text () (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/Utils.cs:171)
     DatabaseLoginManager+<Start>c__Iterator0.MoveNext () (at Assets/DatabaseLoginManager.cs:31)

I don't see the issue, here's my code:

 using UnityEngine;
 using System.Collections;
 using System.Data;
 using System.Data.SqlClient;
 public class DatabaseLoginManager : MonoBehaviour {
     public string url;
     public string username;
     public string password;
     public UnityEngine.UI.InputField usernameInput;
     public UnityEngine.UI.InputField passwordInput;
     public WWW www;
     public string UserAndPass;
     // Update is called once per frame
     public GameObject ErrorMesage;
     void Update () 
     {    
         username = usernameInput.value;
         password = passwordInput.value;
         if(Input.GetKeyDown(KeyCode.Return))
         {
             url = "http://tgsfps.x10host.com/GAMEDB/TGSFPS/Retrieve.php?username=" + username;
             UserAndPass="User="+username+"-"+"Pass="+password;
         }
         username = usernameInput.value;
         password = passwordInput.value; 
     }
 
     IEnumerator Start()
     {
         WWW www = new WWW (url);
         yield return www.text;
         UserPassCheck ();
 
 
     }
 
     void UserPassCheck()
     {
 
     }
 
 
 }


Comment

People who like this

0 Show 0
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
Best Answer

Answer by Bonfire-Boy · Jan 29, 2015 at 01:18 PM

(This relates to the revised code)

The update function is looking at the member field www, which is

a) never being set (your Start function sets a local www variable instead - this is what fafase's comment is hinting at)

and

b) not being checked in Update to see if it's returned.

I would probably

1) remove the WWW member variable altogether,

and

2) put the code that processes the returned WWW object in the function that calls it (ie after the "yield return www").

That way you know you're only ever processing the WWW object after it's returned. Best to check that it's succeeded before using www.text, too.

Comment

People who like this

0 Show 7 · 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 tayyab43 · Jan 29, 2015 at 05:35 PM 0
Share

i removed it and i keep getting this malformed url error, i don't understand why because all i need is the www.text

avatar image Bonfire-Boy · Jan 29, 2015 at 05:38 PM 0
Share

My suggestion involved 2 parts, did you do the second as well?

What happens if you put

Debug.Log(www.text);

immediately after the line

yield return www; ?

avatar image Bonfire-Boy · Jan 29, 2015 at 05:46 PM 0
Share

It's not at all clear what you're trying to do, so it's difficult to help further.

I think you need to learn to get something simple working before adding complexity.

For example, to start with you could remove ALL the www and url code from everywhere except the function with the WWW object in it. Set the URL there, do the WWW call, look at the reply. Once you've got that working you can look at setting the URL dynamically.

avatar image Bonfire-Boy · Jan 29, 2015 at 05:49 PM 0
Share

Specifically, try this...

void Start() { StartCoroutine(doWWW()); } IEnumerator doWWW() { string url = "(insert your url here)"; WWW www = new www(url); yield return www; Debug.Log(www.text); }

avatar image tayyab43 · Jan 29, 2015 at 08:14 PM 0
Share

well, I implemented it and that nearly got it working but now i get this error message:

 NullReferenceException: Object reference not set to an instance of an object
 DatabaseLoginManager.ValidateCheck () (at Assets/DatabaseLoginManager.cs:18)
 DatabaseLoginManager.Update () (at Assets/DatabaseLoginManager.cs:39)


With this code:

 using UnityEngine;
 using System.Collections;
 using System.Data;
 using System.Data.SqlClient;
 public class DatabaseLoginManager : MonoBehaviour {
     public string username;
     public string password;
     public UnityEngine.UI.InputField usernameInput;
     public UnityEngine.UI.InputField passwordInput;
     public WWW www;
     public string UserAndPass;
     // Update is called once per frame
     public GameObject ErrorMesage;
 
     void ValidateCheck()
     {
         UserAndPass = "User=" + username + "-Pass=" + password;
         if (UserAndPass == www.text) 
         {
         
         Debug.Log ("Successful Login");
 
         } 
         else 
         {
         
             Instantiate(ErrorMesage);
         
         }    
     
     }
 
     void Update () 
     {    
         username = usernameInput.value;
         password = passwordInput.value;
         if(Input.GetKeyDown(KeyCode.Return))
         {
             ValidateCheck();
         }
     
     }
 
     IEnumerator doWWW() 
     {     
         string url = "http://tgsfps.x10host.com/GAMEDB/TGSFPS/Retrieve.php?username="+ username; 
         WWW www = new WWW(url); 
         yield return www; 
         Debug.Log (www.text); 
     }
 
 
 
 }

Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Best/Cheapest Way To Have Online Accounts On PC? 1 Answer

WWW.url.text doesnt work! please help! 1 Answer

Smart way of using servers and databases in unity 0 Answers

Custom Editor Send/Get Data To/From Database? 1 Answer

Unity 2017 freezes on login page 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