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 timothykimball · Aug 24, 2012 at 06:20 PM · androidiosnetworkingbackgroundthreads

Background Networking Activity and Unity Run Loop

We are looking for a way to download "concurrently in the background" various resources that our game will need "soon". Our requirements are (1) maximum possible download speed, (2) minimum possible disruption of "foreground" Runloop activities that are driving the game, (3) the solution works extremely well on all the major platforms of interest to us (Android/iOS/PC/Mac), and (4) absence of bugs that debilitate the solution.

If we don't meet requirement #1, then the game has to stop and make the user wait until the background download catches up and delivers the requisite resources. If we don't meet requirement #2, then the background download negatively impacts how the game plays, making it jerky or slow-to-respond, etc.

We've tried and investigated various approaches, including Asset Bundles, WWW, and native C# HttpWebRequest, and non of them meet all of our requirements. Details below.

We'd love to chat with you if you've already figured out how to solve this problem, because we'd rather not reinvent the wheel.

Here are the details of our experience so far:

We have an Android app built in Unity - eventually to also be available via iOS. Alongside the normal foreground activities, we have a background low priority activity of downloading various resources to be used by the app in the foreground.

(Before you ask, Asset Bundles will not work for us as - unless anything has changed recently - they do not work across different versions of Unity - i.e. an asset bundle for Unity 3.4 does not work in Unity 3.5. So an upgrading user will have to re-download all their assets all over again.)

Unfortunately, we have discovered a number of annoying bugs with using the 'WWW' component. These include not updating when there is a loss of network, and no return values from web requests (i.e. 'post'). As such, we are looking to replace our use of WWW with the native C# HttpWebRequest. Unfortunately, we have found using this component in the main Unity Runloop via a co-routine causes the runloop to stall and the UI to freeze.

But placing this same code in a background C# thread (not a co-routine) and then polling that thread's activity does seem to work.

We do not like this approach as this does allow us to schedule this activity in away which is in harmony with the Unity scheduler. We would like the network (and associated CPU) activity to be run in appropriate gaps in the Unity Run Loop. But as far as we can tell, there are only three ways we can specify priority:

  • WWW.threadPriority - we do not want to use WWW so this is mute.

  • Application.backgroundLoadingPriority - As we are not using a Unity component (like AssetBundles) to do the downloading, I am assuming this has no effect?

  • YieldInstructions e.g. WaitForSeconds and WaitForFixedUpdate - My understanding is that these are fairly dumb. They run when they are scheduled to run and do not defer to the needs of the Unity Run Loop?

What we are looking to understand: - Is WWW really fraught with problems or is this just our use of the component? - Has anyone used HttpWebRequest w/ a Unity app successfully? Have they done so in a threaded fashion? - Is there any 'interrupt' or 'priority' architecture in Unity so that background tasks can play nicely w/ the Unity Runloop and not cause glitches or competition?

Any help here is much appreciated!

Thanks, Tim

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

0 Replies

· Add your reply
  • Sort: 

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Get the WiFi IP address of the device 1 Answer

Connecting multiple platforms to one server 2 Answers

Keep network connection from interrupting on iOS multitasking switch 1 Answer

Smartphone multiplayer - NAT problem? 2 Answers

Does UnityEngine.Ping currently support ipv6 addresses on mobile devices? 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