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
1
Question by ina · Jul 07, 2012 at 03:55 AM · yieldthreadingstartcoroutinethread

new Thread vs StartCoroutine

Is new Thread(functionName); basically the same as StartCoroutine(functionName) ?

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

Answer by Eric5h5 · Jul 07, 2012 at 05:01 AM

No, coroutines aren't threads; by default all code in Unity runs in the same thread.

Comment
Add comment · Show 6 · 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 flamy · Jul 08, 2012 at 07:26 PM 0
Share

yup this is correct.... new Thread() starts a function in a different thread...where as startcoroutine does nothin special and runs it in the same thread..

you could note that monodevelop cant open the file from where debug.log is called, if it is in new thread...meaning unity is single threaded by default

avatar image fholm · Jul 08, 2012 at 07:34 PM 2
Share

why is this downvoted? this is 100% correct.

avatar image whydoidoit · Jul 08, 2012 at 07:36 PM 1
Share

No idea - it is certainly correct. Anyone who feels they want to down vote Eric had probably better question their understanding of Unity. +1

avatar image Eric5h5 · Jul 08, 2012 at 07:37 PM 1
Share

Well, I am occasionally wrong. ;) In which case downvotes are fine. But indeed in this case I wasn't wrong.

avatar image ina · Jul 10, 2012 at 04:02 AM 0
Share

what if you don't call subroutines with yield... StartCoroutine(FunctionX) ... it seems it just "thread off" as the next command is issued?

Show more comments
avatar image
4

Answer by whydoidoit · Jul 08, 2012 at 07:35 PM

What happens with a coroutine is that it is run on the main thread every frame and executes until it does a yield - then it will suspend until the yield condition is met. That yield condition is tested every frame and when the condition is met the code in your coroutine resumes. A thread effectively runs at the same time as other code (this is only true when you have multiple cores). Unity cannot support accessing its API from anything apart from the main thread.

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 ina · Jul 10, 2012 at 05:15 AM 0
Share

Hmm, I am still trying to understand access of Unity API apart from the main thread (I guess that is what Eric means by Unity being all on the same thread). I seem able to access Unity API methods such as GetPixels32() and others from the "other thread" (i.e., invoked in a function called from new Thread)

avatar image Eric5h5 · Jul 10, 2012 at 05:26 AM 0
Share

You can't use GetPixels32 in another thread. If you try you'll just get an error at runtime.

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

9 People are following this question.

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

Related Questions

C# WaitForSeconds doesn't seem to work ?? 2 Answers

Thread ending prematurely? 2 Answers

Fire and forget coroutines 1 Answer

yield return on WWW never coming back? 0 Answers

will monobehaviour stay alive after DOTS? 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