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 Case23 · Jul 06, 2010 at 05:22 PM · multithreading

Using BackgroundWorker Class let Unity crash.

I try to implement a BackgroundWorker for my Database, so that my applikation does not freeze whenever i try to get huge amount of data out of it.

http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx

All things which happening in my BackgroundWorker is only the Database select execution. I save my results in a List.

At the BackgroundWorker.completed Event i start creating gameobjects based on the database entrys, and than Unity crashes. Always with the error messages:

"!Thread:EqualsCurrentThreadID(m_MainThreadID)"
"!Thread:EqualsCurrentThreadID(GetPersistentManager().GetMainThreadID())&& mode != kCreateObjectDontRegisterInstanceID"
"m_ThreadCheck&&!Thread:EqualsCurrentThreadID(m_ThreadID)"

Is it possible to multithread in Unity3d? And if. Do you have a hint where my mistake could be?

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

Answer by Mike 3 · Jul 06, 2010 at 05:32 PM

You can't access most of the unity API from threads, it'll just blow up like you've seen

What you need to do is buffer the creation requests into an array or list, then read them from Update

This goes for moving objects (via physics or transform), creating components and gameobjects, textures, and many other things - basically everything extending from UnityEngine.Object (And some which don't on top of that)

Comment
Add comment · Show 3 · 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 Case23 · Jul 06, 2010 at 05:49 PM 0
Share

I did this already. $$anonymous$$y problem only was that when i made my database.command execution. And sometimes i asked for kinda 2k and more entrys, unity freezed until the whole request was done. I only wanted this done in a seperate thread. What i did now was: $$anonymous$$oved all the GameObject creation code outside from the thread complete Handler. Than, in a seperate update function i check if the backgroundworker is not busy, and if there are new dbResults. If so it starts creating the Gameobjects (one per frame), which now works fine and fast. :)

avatar image Mike 3 · Jul 06, 2010 at 05:53 PM 0
Share

Yup yup, that's similar to how I do it too :)

avatar image 3Duaun · Feb 09, 2011 at 02:25 AM 0
Share

can that method work on iOS? Has anyone tested in in Unity3.x on iOS?

avatar image
0

Answer by Oksana Iashchuk · Sep 26, 2012 at 02:07 PM

Cool, you could lock here for multi-threading http://u3d.as/content/orange-tree/thread-queue

it's a part of http://u3d.as/content/orange-tree/sqlite-kit which actualy already has asynchronous sqlite database processing.

good example: http://forum.unity3d.com/threads/152557-Meet-new-easy-thread-queue-asset!

Comment
Add comment · 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

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

1 Person is following this question.

avatar image

Related Questions

Is it possible to query the Unity (3.0) transform tree from a secondary thread? 1 Answer

CompareBaseObjectsInternal can only be called from the main thread. 1 Answer

Multithreaded Input Detection 2 Answers

Unity Multithreading only works partial 0 Answers

Getting texture size off main thread 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