• 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
Question by gamenovice · Feb 08, 2014 at 05:09 PM · coroutinedialoguecoroutine errors

Odd Coroutine behavior

So I have been at this problem for the last few days and I am completely stumped. Here's the scenario:

the way I have my game setup is in Navigation phase and Battle phase, both occur in the same scene (think 2d rpg with the battle gui layered over the navigation view). My problem occurs when trying to use a coroutine to display text and then use another one to wait for user input. In the Navigation phase, it works perfectly, but for some reason, in the battle phase if you were to press spacebar (the key that proceeds to the next dialogue box) prematurely, it'd glitch the dialogue box system and have it dissappear for a moment.

Now for the sake of brevity, I will post the relevant code snippets since the source code itself is too long (Let me know if I need to put in more info though) this is how the actual coroutine utilizing the dialogue logic looks:

 IEnumerator CUTSCENE_MAIN() //do not worry about this, it works fine
 {
       /* the two coroutines in question */
         yield return DialogueMC ("(dialogue...)");
 
         yield return WaitForUserInput();
       
         yield return DialogueMC ("(dialogue...)");
 }

and this is how I've declared both of the coroutines in question:

     IEnumerator DialogueMCIE(string text){
         GUIManager.PushMCDialogueBox (text, GUIManager.MainCharacterName);
         yield return StartCoroutine (TextScroll(GUIInterface.instance.MC_dialogueText,text));
 
     }
     public Coroutine DialogueMC(string text){
                 return StartCoroutine(DialogueMCIE (text));
         }
 
 IEnumerator WaitForUserInput(KeyCode keyCode)
     {
                 
     while (!Input.GetKeyUp(keyCode)) {
                                 yield return null;
 }
 
         GUIManager.PopEverything ();//this is what clears the dialogue box to allow for preparation of a new dialogue box
                 
                         
     }
     public Coroutine WaitForUserInput(){
         return StartCoroutine(WaitForUserInput(KeyCode.Space));
     }


I have even tried to put yield return new waitforseconds in between the get it to wait before accepting user input to move on, but to no avail. it's like it disregards whatever command i type in and has the user skip over it anyway. my theory is that coroutines do not work as sequentially as i was hoping. like it goes ahead and starts the dialogueMC coroutine, but like a thread, and moves down the script to start the next coroutine, which is the only possible explanation as to why its accepting the spacebar input prematurely.

Again, I honestly don't understand why this is happening, but if anyone has any idea, it would help tremendously. If this is not enough info, please let me know and I will post on here the battle script in question and any relevant classes, or if a video suffices I will try and record that instead.

Comment

People who like this

0 Show 0
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Why is my coroutine skipping a method? 1 Answer

WaitForSeconds Not Working 4 Answers

StartCoroutine_Auto can only be called from the main thread. 1 Answer

Why doesn't a coroutine start executing from beginning when I start it again? 1 Answer

Coroutine Won't Stop Using IEnumerator 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