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 Fattie · Jan 16, 2012 at 06:27 PM · monodevelopbackgroundyieldthreadsinterrupt

Interrupting a long process: progress watching?

Say you are running a LONG process. For example, ten seconds.

So you have an ordinary OnGUI, button, and the button calls "_runLongCalculation();"

_runLongCalculation() will use the current Unity scene.

For example it may do do ray casting, or use other unity functions based on the scene.

In a word:

While that ten second routine is running: how do you keep some sort of animation (for example) going?

(Or you may want to - say - move something in the scene: a cloud could floats over while the calculation is running.)

A progress thermometer .. anything.

Essentially - what do you do when you are running _runLongCalculation (10 seconds) and you want some sort of "foreground" activity to run in the meantime?

Any ideas? Thanks!

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
3
Best Answer

Answer by Bunny83 · Jan 16, 2012 at 07:15 PM

If the long process doesn't use the Unity API, I strongly recommend a seperate thread. You just have to be careful with shared ressources. If you need anything of the Unity API you have to use yield in some clever way since the whole API isn't tread-safe.

edit Well like already said, if you use ANY functions form the Unity API you can NOT use threads. The only way is to use coroutines. You need to place some yields at clever points in your code to give the rest of yout application / game some processing time and to keep it running.

Unity isn't designed for pure processing with a little interface. It's a game engine. If you just use a few things from Unity like raycasts you could use threads and implement some kind of task-system so the other thread can create a task (raycasting somewhere) and the Unity main thread execute these tasks. This task-system has to be completely thread safe so you need to use a lock / semaphore / mutex to keep both threads in sync.

It won't save any processing time, because the threads wtill have to wait for each other, but depending on your how your "long processing" is implemented it might be easier.

Comment
Add comment · Show 1 · 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 Fattie · Jun 09, 2012 at 09:21 AM 0
Share

"Unity isn't designed for pure processing with a little interface. It's a game engine."

This is a superb point.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Cannot watch local variable value if the function contains a "yield" 1 Answer

Background Networking Activity and Unity Run Loop 0 Answers

Threading in Unity 6 Answers

Running a function in the background 0 Answers

Is this the best way to do an AutoParallax Background ? 1 Answer


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