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
17
Question by Graham-Dunnett · Oct 07, 2009 at 04:53 PM · threadsscripting-underthehood

Is the Unity API threadsafe?

I notice that Unity supports background loading of asset bundles, so I guess uses threads. Can I use threads in my own script and plugins? Are there any issues to be aware of?

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

Answer by Lucas Meijer 1 · Oct 18, 2009 at 01:42 PM

No.

Every call you make into the Unity API, must be done from your main thread. It is possible for you to create your own threads, to make whatever calculations you like, however, the additional threads you create yourself should not call any Unity functions. They should communicate their results back to the mainthread, which can then call the Unity functions.

If you try to do this anyway, it might accidentally work, however future Unity updates (including those of the webplayer) are very likely to make this break.

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 Keli Hlodversson · Nov 10, 2009 at 12:23 PM 5
Share

To help you avoiding using the Unity APIs in a non-threadsafe manner, Unity 2.6 will now throw an exception in the editor if your code invokes API functions from a thread that's not the main thread.

For performance reasons this check is disabled in published builds however.

avatar image jashan · Dec 10, 2009 at 06:06 PM 0
Share

Hey $$anonymous$$eli, thanks for that information (and also thanks to whoever implemented that) - sounds like a great idea to me to make Unity more robust!

avatar image Graham-Dunnett ♦♦ · Jan 12, 2010 at 08:50 PM 0
Share

the assert you get is:

m_ThreadCheck && !Thread::EqualsCurrentThreadID(m_ThreadID)

avatar image user-1883 (google) · Mar 29, 2010 at 07:04 AM 0
Share

I have been running into this issue, without explicitly starting a new thread. The one thing I suspect is the root of this evil is my usage of a static class, my lazy way of keeping track of my "globals". When trying to asyncloadlevel from my static class i get the dreaded m_ThreadCheck message

avatar image yoyo · Feb 24, 2011 at 03:59 AM 0
Share

Dislike. ;)

Show more comments
avatar image
4

Answer by $$anonymous$$ · Nov 07, 2009 at 09:48 PM

You can achieve some of the advantages of threads by using coroutines - see the Coroutines and Yield overview in the Scripting Reference.

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 Ashkan_gc · Dec 31, 2009 at 03:21 PM 0
Share

this question is asked and answered by unity technologies staff to $$anonymous$$ch us something. someone that wants to use threads already knows coroutines. :D threads are some of the most advanced stuff in program$$anonymous$$g. however using them in C# is alot easier than C++. unity's scripting engine is the best choice that they made! thank you guys

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Is it okay to mark well-known events as private? 1 Answer

play animation sequence 3 Answers

What are the benefits of using Invoke over Coroutine or vice versa? 1 Answer

WorldToScreenPoint in Update/OnGUI: Bad Performance 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