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 FunctionR · Nov 11, 2013 at 02:15 PM · c#instantiatemonobehaviourthreads

Threads for Instantiate

Problem

I start populating my scene with enemies. If I want to instantiate n enemies of type Enemy_A, that takes time that some other subsystem could be doing something.

Idea

I would like to create a thread that instantiates enemies.

Bigger Problem

It seems that Unity won't allow me to call the MonoBehavior functions like MonoBehavior.Instantiate() from a thread, even if that thread is independent from Unity. (I got this notion from this Previous Thread Question).

Is there a way around this problem? I thought of using Application.LoadLevelAdditiveAsync but I would prefer something else. Any suggestions?

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
0

Answer by Bunny83 · Nov 11, 2013 at 04:13 PM

Well, if you have actually read the other question you have linked (including the answers), it should be clear that there's no way to use any unity api function from another thread but the main thread. A thread is a thread, no matter if it's a "c# thread" or not. The only way to load something in a background thread is to use unity's pro features like Application.LoadLevelAdditiveAsync. That's it. The API is not thread-safe and there's no way to make it thread-safe.

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 FunctionR · Nov 11, 2013 at 04:25 PM 0
Share

It was kind of obvious that I read the answers, that is exactly what I am citing above. It might not have been obvious, to you at least, the question and answers are from 2011 and there might be new information on the matter. Thank you though, now I know there is nothing new.

avatar image Bunny83 · Nov 11, 2013 at 09:58 PM 0
Share

Well, that won't change in the future. The way the api works, they would need to implement tons of locks / semaphores / other synchronizing methods to make everything thread-safe. That would have a horrible impact on performance.

The chance that they change this in any future version is below 1%

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

17 People are following this question.

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

Related Questions

Distribute terrain in zones 3 Answers

Classes, MonoBehaviours C# 2 Answers

Multiple Cars not working 1 Answer

Using a non-monobehaviour class file 1 Answer

Should I make my own Start / Update? 2 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