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 /
  • Help Room /
avatar image
0
Question by unity_l5xXAIOOvQ9ScQ · Aug 23, 2018 at 11:36 AM · unity 5script.

Make a "Progress Bar" during a recursive method in C#

Hello !

I'm trying to make a GameObject turning in each frame (like a kind of "wait/progress bar") during a very long recursive method. My Issue is that that object does not turn as expected because my Unity Program stay stuck on a single frame (because the recursive method do not free my frame I suppose). How can I manage to do that ?

my code looks like :

 method 1{
     StartCorountine("cr1");
 }
 IEnumerator cr1(){
     displayContext(); // does not matter
     yield return new WaitForFixedUpdate();
     displayTurningObject();
     veryLongRecursiveMethode();
     hideTurningObject();
 }

I'm quite new with Unity so don't hesitate to ask for precisions.

Thanks for Help

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

Answer by JVene · Aug 23, 2018 at 10:27 PM

Without more context I can only guess. However, you've already identified the problem. Any method that is going to take a long while is going to freeze the Unity game engine if it runs on the main Unity thread. There will be no hope of displaying anything, as no frames will be processed.


This is what threads are for. Without having information on what your recursive routine does (in particular, what data is it processing, does it get involved with Unity objects that the engine may be using at the time), I can't say more than the most general statements.


You are going to want to review some documentation on starting threads. You may need a tutorial on how to use them. Search on the subject and experiment, perhaps even in a stand alone C# project to understand how they work. Doing this will allow the Unity engine to continue running, which is required in order for your animated wait graphics to display.


Coroutines are not threads, they are basically a mechanism for Unity to call a list of function objects (in C++ we call them functors, a related concept) from a list formed by registering coroutines, which Unity calls at an appropriate time within the order of execution. Coroutines can't solve this problem.

Comment
Add comment · Show 4 · 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 unity_l5xXAIOOvQ9ScQ · Aug 24, 2018 at 06:45 AM 0
Share

Thanks for your answer ! Unfortunately I'm working with a version of Unity that can't use (as I was told) Threads. I will check this information but I think I am in a dead end.

avatar image JVene unity_l5xXAIOOvQ9ScQ · Aug 24, 2018 at 06:59 AM 0
Share

What version are you using? I've found articles that discuss threading in Unity at least as far back as 2012. Even if it were true, there are alternatives. For one, there are ways of reconfiguring a recursive algorithm such that it can run in short bursts over successive Updates until the task is completed (it's an ooooold concept going back to my days in Windows 3.1 and DOS :) ).

avatar image unity_l5xXAIOOvQ9ScQ JVene · Aug 24, 2018 at 07:10 AM 0
Share

I'm using Unity 5.6.5. $$anonymous$$aybe my informations were wrong :D I will try to parallelise that recursive function.

avatar image Hellium unity_l5xXAIOOvQ9ScQ · Aug 24, 2018 at 06:59 AM 1
Share

You can use threads in Unity. But you can't call Unity-related functions in a thread not handled by Unity itself (the main thread)

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

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

Multiple GameObjects with same Script 1 Answer

[Unity 3D] [C#] Do you have problems working with non-English languages ​​(Korean)? 영어가 아닌 언어(한국어)로 작업시 문제가 생기나요? 0 Answers

Make humanoid fall if lifts both the legs or if the humanoid looses balance at runtime. 0 Answers

Set the username with an inputfield ? 3 Answers

How can I add both animator and script rotation on Game object? 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