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 Bunnybomb7670 · Jun 12, 2013 at 10:42 PM · coroutineissueyieldwaitforsecondswait

Wierd issue with Coroutines?

I am finding it very annoying to just yield in code. I have this :

 IEnumerator reArrangeChunkOrderToMatchSystem(int dir)
     {
         GameObject[] newData;
 
         if (dir != 6)
         {
 
             switch (dir)
             {
                 case 0:
 
                     newData = new GameObject[loadedChunkRadius * worldChunkDefaultLoadedHeight];
 
                     for (int i = 0; i < loadedChunkRadius * worldChunkDefaultLoadedHeight; i++)
                     {
                         newData[i] = ChunkInstance;
                     }
 
                     int temp = 0;
                     for (int i = 0; i < loadedChunkRadius * worldChunkDefaultLoadedHeight * loadedChunkRadius; i++)
                     {
                         yield return new WaitForSeconds(0.1f);
                         Vector3 a = loadedChunks[i].transform.position;
                         if (a.x == centerChunk.pos.x - 96)
                         {
                             loadedChunks[i].transform.position += new Vector3(16 * (loadedChunkRadius - 1), 0, 0);
                             Vector3 vec = new Vector3(loadedChunks[i].GetComponent<ChunkMain>().chunk.pos.x, loadedChunks[i].GetComponent<ChunkMain>().chunk.pos.y, loadedChunks[i].GetComponent<ChunkMain>().chunk.pos.z);
                             reloadChunkDataOrGenerateNew(vec, loadedChunks[i]);
                             temp++;
                         }
 
                     }
 
                     break;

The issue is that it wont wait for 0.1 seconds, it will just literally stop the whole function from working. I dont know whats going on and there are no errors but everything after the yield doesnt work any more. Am i doing something obvious that is wrong?

I also started the coroutine in the start function so it should work.

 void Start ()
 {
         StartCoroutine("reArrangeChunkOrderToMatchSystem",6);
 }

All i want to really do is add a delay to the part where the yield is currently placed so that it slowly streams the data rather than doing everything in a chunk.

Thanks,

Comment
Add comment · Show 9
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 Owen-Reynolds · Jun 13, 2013 at 12:00 AM 0
Share

How large is ChunkRadius squared times WorldHeight? $$anonymous$$aybe it is running, just taking forever. Try some Debugs.

Is centerChunk moving in that 10th of a second? The odds of a.pos.x being exactly equal to center.pos.x-96 are virtually nil, if so.

avatar image Bunnybomb7670 · Jun 13, 2013 at 07:44 AM 0
Share

I instantiate my system on a grid, it is dynamically offset in sets of 16 so it will always be equal to an integer, nothing moves them around either, it works perfectly fine without the yield but once i use the yield it doesnt work, no errors, it just doesnt work.

avatar image Bunny83 · Jun 13, 2013 at 02:41 PM 0
Share

Like owen said, how many iterations are you doing in your for loop? For example if you have 16 16 128 (a bit $$anonymous$$ecraft related :D) you will have 32k iterations. Even when you yield 0.00000001s the yield will at least take one frame, so just assume we have a constant framerate of 60 fps that would mean your for loop takes 546 seconds or over 9 $$anonymous$$utes. So can you please give us your bounds.

avatar image Bunnybomb7670 · Jun 13, 2013 at 02:58 PM 0
Share

it is 11x3x11 ( the loaded chunks in the world at once ) , basically 363 loops. the reason i use variables is so that i can make the system dynamic, also it is the same variable X itself because the x and z loaded range is always the same.

avatar image Bunny83 · Jun 13, 2013 at 03:07 PM 0
Share

Of course, we never said you shouldn't use variable, but it's hard to debug the script if you don't know whether the value in those variables are in the range 2-5 or 200k - 5m

With your delay of 0.1 second it takes about one $$anonymous$$ute to complete the loop.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Jun 13, 2013 at 01:12 AM

The yield is correct - it should cause a 0.1 delay each loop iteration, and without hanging Unity. Maybe your problem has another cause. Is this for correct?

 for (int i = 0; i < loadedChunkRadius * worldChunkDefaultLoadedHeight * loadedChunkRadius; i++){

loadedChunkRadius is being multiplied by itself and by worldChunkDefaultLoadedHeight, and if there's no enough loadedChunks elements you will get a runtime error (Out of Range), aborting the script. Should loadedChunkRadius be multiplied by itself?

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 Bunnybomb7670 · Jun 13, 2013 at 07:43 AM 0
Share

Yes it should be multiplied by itself, i use variables ins$$anonymous$$d of numbers because it allows the system to be changeable. It works fine without the yield, its just as soon as i put that yield in there, it will just not execute the code, it wont give any errors either, it just, doesnt work when i add the yield. which is really really wierd!

avatar image
0

Answer by AntiLunchBox · Jun 13, 2013 at 05:26 PM

im a little confused how your code is getting there in the first place. You are calling that function with 6 as the dir parameter...However, in the beginning it checks if dir != 6 ???

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 Bunnybomb7670 · Jun 13, 2013 at 06:40 PM 0
Share

I did that because it was calling it in the start function and giving an error because it was initialized , i dont get why that matters what parameters i set, i tried 0 and it still doesnt work. I really dont get why it wont work.

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

18 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

Related Questions

Getting an error when trying to yield 2 Answers

yield works, but yield WaitForSeconds does not? 1 Answer

Alternative for semaphores in Unity? 2 Answers

Playing footsteps with interval 1 Answer

Load Level when dead for 1 second 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