Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 XenonSpher · Oct 03, 2016 at 09:11 AM · importcoroutineruntimemultithreadingunresponsive

StartCoroutine doesn't work for me to remove momentary unresponsive when loading OBJ file at runtime. Multithreading is a good way to go? any help?

my app. https://www.dropbox.com/s/a6evzf2hw0jzjy1/Backup%20RunTime%20OBJcomplete.rar?dl=0

is a simple runtime obj importer that could also edit it at runtime the problem is it takes. a period of time to load and has a momentary unresponsiveness when loading. the reason of this momentary unresponsive is because of the import script. it gathers data, set it, change it, loops it again and many more in just a short amount of time. the script is from

https://www.assetstore.unity3d.com/en/#!/content/49547

this is how I emplemented corountine:

   public IEnumerator ForLoadOBJ()
     {
         LoadOBJFile(PlayerPrefs.GetString("PathString"));
         //the use of PlayerPrefs is just temporary until I could make this unresponsiveness and slow loading go away
         yield return null;
     }

and the code I use for when I click the import button:

 StartCoroutine(obj.ForLoadOBJ());

using the codes above doesn't help.. its just feels like I'm not using Coroutine. unresponsive is still there.

any help regarding to using corountine or multithreading would very much apreciated. any questions ask would be answered as well. please and thank u.

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 MrEastwood · Oct 03, 2016 at 02:10 PM

Coroutines still run on the main thread. The only way a coroutine can make your app more responsive is if you can break down the work and then not do all of it at once. So for instance you can put yield return inside of a loop, and then you would do only one iteration of the loop each update instead of all of the iterations in one update.

However this is not the case here. You have a single instruction that is taking up all your time. Without a good point to yield, this really isn't any different from doing that one big instruction in Update.

So if you want to dive into the implementation of LoadOBJFile you could modify it to be coroutine friendly. But i would go with threading here. It will solve your problem but it will give you some new ones too if you are inexperienced with threads. Things to look out for:

  1. Make sure you don't start your thread more than once. Your call will now be asynchronous meaning that the result will arrive at a different time from the call.

  2. Use locking! Don't do things like if (!alreadyLoading) loadTheThing(), because the bool could change in between the test and the call, causing you to load twice even though you checked for it.

  3. Only the main thread is allowed to touch gameobjects and components. So you could load your object asynchronously, but only if it gives you the vertex data. Then, when the data is loaded you take the data on the main thread and only then can you assign it to your meshfilter for example.

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

66 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 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 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 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

How to add a loading sequence/scene/etc. when importing something at runtime to avoid it going unresponsive? 0 Answers

Importing .fbx Files During Runtime 1 Answer

WebGL prevent Unresponsive script warning 1 Answer

How to use MultiThreading to remove momentary unresponsiveness 0 Answers

Instantiating many objects during update lags 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