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 tr3dent · Jan 10, 2014 at 09:39 AM · c#errorienumeratorstartcoroutine

Why is my StartCoroutine within a IEnumerator bombing Unity? C#

The below code bombs Unity without an Error message straight to my OS. The offending line is the StartCoroutine within CheckMaximiseMenu IEnumerator.

Is this issue a lack of Co-routine knowledge or a legitimate bug ?

 using UnityEngine;
 using System.Collections;
 
 public class GUIManager : MonoBehaviour  {
 
     void Start () 
     {    
         StartCoroutine(CheckMaximiseMenu(new Rect(Screen.width - 10, 0, 10, Screen.height)));
     }
 
     IEnumerator CheckMaximiseMenu(Rect pRect)
     {
         while (!pRect.Contains(Input.mousePosition))
                 yield return 0;
         StartCoroutine(CheckMinimiseMenu(new Rect(Screen.width - 50, 0, 50, Screen.height)));            
     }
 
     IEnumerator CheckMinimiseMenu(Rect pRect)
     {
         while (!pRect.Contains(Input.mousePosition))
             yield return 0;
         StartCoroutine(CheckMaximiseMenu(new Rect(Screen.width - 10, 0, 10, Screen.height)));
     }
 
 }
Comment
Add comment · Show 5
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 GameVortex · Jan 10, 2014 at 09:41 AM 0
Share

Hard to tell. The code you have there is perfectly fine. Coroutines can be started from within coroutines without problem usually. Do you have anything else running in your scene?

avatar image tr3dent · Jan 10, 2014 at 09:51 AM 0
Share

There is nothing else in my scene, bar the actual gameobject the said script is attached too. Presumably its a bug ? can anyone replicate ?

Running unity v 4.3.0f4

avatar image GameVortex · Jan 10, 2014 at 10:42 AM 0
Share

@$$anonymous$$olodej You are very right. I totally missed that.

@tr3dent The problem would stem from that not all code paths return a value. You need to put a yield return 0 outside the while loop as well, or use a do-while loop ins$$anonymous$$d.

avatar image Invertex · Jan 10, 2014 at 11:03 AM 0
Share

What $$anonymous$$olodej said seems to be the case here. What are you trying to achieve? It's unusual that you would need to start a Coroutine for GUI on Start().

Are you trying to make a GUI element expand out when someone mouses over it? In such a case, you can simply do that in your Update() function, without the Coroutine overhead. Here's an example:

 private Rect pRect;
 
     void Update () {
         if(pRect.Contains(Input.mousePosition))
         {
             pRect = new Rect(10,0,90, Screen.height);
         }
         else
         {
             pRect = new Rect(10,0,10, Screen.height);
         }
     }
     
     void OnGUI()
     {
         if(GUI.Button (pRect,"pRect"))
         {
         }
     }
avatar image tr3dent · Jan 10, 2014 at 11:08 AM 0
Share

No you are right, Invertex - That would be the way to do it. I was testing some things out and ran into this issue along the way.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Kolodej · Jan 10, 2014 at 10:13 AM

Hi, if I am not wrong, there is a infinite loop of calls between CheckMaximiseMenu and CheckMinimiseMenu. If the mouse position is at "Maximise" coords, then is also the "Minimise" condition fulfilled.

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 tr3dent · Jan 10, 2014 at 10:56 AM 0
Share

Thanks kolodej, Was a logic error, I can't mark this as answered :(

Good thing its home time soon :).

avatar image Jamora · Jan 10, 2014 at 11:51 AM 0
Share

I marked it answered for you.

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

22 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

Related Questions

Multiple Cars not working 1 Answer

Loop with WaitForSeconds in IEnumerator appears to be incorrect by 10-15% 2 Answers

Distribute terrain in zones 3 Answers

I can't start a coroutine. I get a weird message from visual studio 1 Answer

C# How to ping servers and get server latency? 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