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 13, 2013 at 01:23 PM · c#yieldwaitforseconds

Is it possible to have a yield manager?

I am not sure why this wont work but, say if I dont want to have my functions all IEnumerators, could I instead have a function what manages yields? It doesnt work when I call it for some reason.

 void Awake()
     {
         StartCoroutine("fakeYield", 0);
     }

and this is the function :

 IEnumerator fakeYield(float duration)
     {
         Debug.Log("Waiting for "+duration);
         yield return new WaitForSeconds(duration);
 
     }

and I am calling it like this :

 void 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++)
                     {
                         
                         Vector3 a = loadedChunks[i].transform.position;
                         if (a.x == centerChunk.pos.x - 96)
                         {
                             fakeYield(0.1f);
                             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;

It debugs it once, during the awake function for some reason and whenever the loop calls it, it doesn't call the function for some reason...

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 · Jun 13, 2013 at 01:37 PM

Your fakeYield function is a generator function. It doesn't execute any code inside your function, but it returns and object which can be used to "iterate through your code". This object need to be passed to StartCoroutine and Unity's coroutine scheduler will handle the iteration for you.

When you just call:

 fakeYield(0.1f);

It will create an iterator object which you just throw away, so it does nothing. Besides that your fakeYield has no use since there's nothing after your

 yield return new WaitForSeconds(duration);

The reArrangeChunkOrderToMatchSystem function can't be "paused" since it's not a coroutine.

What do you actually want to do?

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

I want to add a delay, look at this :

http://answers.unity3d.com/questions/473703/wierd-issue-with-coroutines.html#answer-473803

$$anonymous$$y other question which is what im trying to do to get around the issue im having, i just want to add a 0.1 second delay inbetween the for loop but i am really struggling with this stupidly simple code.

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

Your other version is by far more correct than this one. You can't add a delay in a normal function. It has to be a coroutine.

How and where do you call your reArrangeChunkOrderTo$$anonymous$$atchSystem coroutine in your other question?

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

I was calling the startcoroutine in the start function and trying to call the function normally in the code, i guess i cant really just call the ienumerator function normally can i?

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

15 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Waiting between pingpong loops 2 Answers

What is wrong with this use of WaitForSeconds? 1 Answer

C# yield waitforseconds 3 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