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 dkfister · Apr 22, 2014 at 05:52 PM · c#webplayerwwwienumerator

WWW Request runs in Editor but not in Webplayer

As the title says, I'm sending an WWW request to my webserver that has a crossdomain policy and everything working correctly. As also mentioned, everything works perfectly fine without and errors or anything in the Editor.

But when trying to run the same exact game in a Webplayer build, it simply just freezes, not even my Try-Catch fires.

This is the part, where I try to fire the WWW Request code:

 if(GUILayout.Button("Create Channel", GUI.skin.button)) {
     try {
         int channelID = int.Parse(DataHandler.self.CreateChannelID(ChannelName));
         if(channelID != 0) {
             Message = "Channel Created!";
         } else {
             Message = "Channel Name already exist!";
         }
     } catch(UnityException err) {
         Message = err.Message;
     }
 }

And this is the part, where the 'behind the scenes happen, A.K.A the WWW Request. Note that I have edited the urlRequest for this question, for security purposes of mine, It's tested in browser and works there aswell.

 public string CreateChannelID(string ChannelName) {
     string urlRequest = "http://mywebsite.com/game/AddChannel.aspx?ChannelName=" + ChannelName;
     
     WWW request = new WWW(urlRequest);
     StartCoroutine(YieldRequest(request));
     
     while(!request.isDone) {}
     
     return stripString(request.text);
 }
 
 private IEnumerator YieldRequest(WWW request) {
     yield return request;
 }
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
Best Answer

Answer by gfoot · Apr 22, 2014 at 07:41 PM

Line 7 does a busy-wait for the request to complete. Depending on the WWW implementation (which varies between platforms), the request may or may not be able to complete in the background - on some platforms it requires your code to return control to Unity. So you need to avoid busy loops like that - they are really bad practice anyway.

The easiest way to resolve this is probably to move all of the response to the button getting pressed into a coroutine. Then that coroutine can yield waiting for the request to complete, without blocking OnGUI. Something like this:

     if(GUILayout.Button("Create Channel", GUI.skin.button)) {
         StartCoroutine(DoCreateChannel());
     }

 ...

 private IEnumerator DoCreateChannel() {
     string urlRequest = "http://mywebsite.com/game/AddChannel.aspx?ChannelName=" + ChannelName;
 
     WWW request = new WWW(urlRequest);
     yield return request;
 
     string result = stripString(request.text);

     int channelID = int.Parse(result);

     if(channelID != 0) {
         Message = "Channel Created!";
     } else {
         Message = "Channel Name already exist!";
     }
 }

If you need some of the processing to be encapsulated elsewhere then you can do that but it's best if the WWW request itself is handled here. Otherwise you end up needing to chain coroutines together, and you quickly reach a point where pretty much every function involved has to be a coroutine, and it's all badly coupled.

Comment
Add comment · Show 2 · 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 dkfister · Apr 22, 2014 at 08:24 PM 0
Share

Tried your solution that makes sense.. It still works no problem in the Editor. After more debugging in the Webplayer, I found that it still doesn't work there, but just simply stops when it reaches the yield return. It never goes beyond that point, which is my current problem. This guy has a very similiar problem to what I'm having right now: http://answers.unity3d.com/questions/154299/yield-return-request-never-returns.html

avatar image gfoot · Apr 22, 2014 at 10:17 PM 0
Share

I don't know why that would happen. You could check the webplayer logs in case there are error messages in there - some things throw exceptions and unless you look in the logs you'll never know about it.

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

21 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

Related Questions

Yield return request never returns 0 Answers

How to optimize the build game for unity webplayer? 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Get session of web application by web player 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