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 LethalBeauty23 · Jun 18, 2015 at 07:05 PM · c#errorcoroutine

Error Coroutine couldn't be started!

My script has been working fine for the past few weeks but suddenly I get a console error when I run it and the message I want to display on the screen isn't displayed.

Here is my script:

 using UnityEngine;
 using System.Collections;
 
 public class CutSceneLight1 : MonoBehaviour {
     
     public int wait;
     public GUIStyle text;
     string message = " ";
     
     
     //GUI Box
     void OnGUI() {
         GUI.Label((new Rect(600,400,200,200)),message ,text);
     }
     
     //Displaying text
     IEnumerator OnTriggerEnter(Collider otherObjective){
         if (otherObjective.tag == "Player") {
             
             message = "Message here";
             StartCoroutine(message);
             yield return new WaitForSeconds(wait);
             message = "Another message here";
 

What I want to happen is for the player to cross the collider which is set as trigger and then the messages play.

Please help me I need to fix this as soon as possible. Thanks!

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

3 Replies

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

Answer by Ibzy · Jun 23, 2015 at 03:17 PM

Not entirely sure what you're trying to accomplish with the messages, but you are trying to call a string as a function? ("message" is a string).

Also, OnTriggerEnter should be a void. I imagine you want to apply StartCoroutine(displayMessage(message)); to an IEnumerator displayMessage(string msg); function?

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 LethalBeauty23 · Jun 23, 2015 at 03:38 PM 0
Share

Sorry I'm a bit of a noob.

I want the messages to be displayed on the screen when you play the game and I want them to each be displayed for a certain length of time before moving on to the next message. (I've put "$$anonymous$$essage here" because I don't know what I want to be printed on the screen just yet)

I didn't use void for OnTriggerEnter because it then wouldn't let me use WaitForSeconds and so I used IEnumberator ins$$anonymous$$d and this worked perfectly until a week later when all of a sudden nothing was working, which I found very odd.

Thank you for your help so far I greatly appreciate it! Although I'm not entirely sure what you are suggesting I do, sorry, could you explain a little more?

avatar image Ibzy · Jun 23, 2015 at 03:51 PM 1
Share

So everything worked perfectly before? Your messages were appearing on the screen also?

Looking again this might literally be as simple as removing the line StartCoroutine(message);

Give that a go and let me know.

avatar image LethalBeauty23 · Jun 23, 2015 at 04:02 PM 1
Share

Everything is working fine now! Thank you!

avatar image
1

Answer by OctoMan · Jun 23, 2015 at 03:30 PM

Why not start the coroutine with the Trigger/collider?

 void OnTriggerEnter(Collider otherObjective)
 {
 if(otherObjective.tag == "Player")
 {
 StartCoroutine(Messanger());
 }
 }
 
 private IEnumerator Messanger()
 {
 //do your messages stuff here...
 message = "Message here";
 yield return new WaitForSeconds(wait);
 message = "Another message here";
 }

Might have some typos!

Here is a small textoutputmanager i wrote for my current project. it will show for 3 seconds a specific message and will disable after that.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class TextOutPutManager : MonoBehaviour {
 
     //panel ggf.
     public GameObject textPanel;
     //text field output
     public Text MessageOutput;
     //string message
     public string message = "";//this is the message to show
     //string incoming message
     public string incomingMessage = "this is the message send from outside";
 
     //bool showtext
     public bool showtext = false;
 
     // Use this for initialization
     void Start () 
     {
         textPanel.SetActive(false);
     }
     
     // Update is called once per frame
     void Update () 
     {
         if(showtext)
         {
             StartCoroutine("Timer");
         }
         else
         {
             StopCoroutine("Timer");
         }
 
 
     }
 
     private IEnumerator Timer()
     {
         message = incomingMessage;
         MessageOutput.text = message;
         textPanel.SetActive(true);
         yield return new WaitForSeconds (3);
 
         message = "";
         MessageOutput.text = message;
         textPanel.SetActive(false);
         showtext = false;
     }
 }
 

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 LethalBeauty23 · Jun 23, 2015 at 03:48 PM 0
Share

This doesn't seem to work. I tried it out and I don't get any errors but the message doesn't appear on the screen. Thank you anyway.

avatar image LethalBeauty23 · Jun 23, 2015 at 03:49 PM 0
Share

I've just seen the rest of your comment and will try that out now. :)

avatar image LethalBeauty23 · Jun 23, 2015 at 03:56 PM 0
Share

I've just tried to run your script to see if it would help me, however I get an error saying that the type or namespace name 'Text' could not be found.

avatar image OctoMan · Jun 23, 2015 at 04:49 PM 0
Share

The namespace

 using UnityEngine.UI;

needs to be in top as it is in my script, of course you need toi create a textpanel with a field inside, and drag the parts in the inspector to make it work.

To make it active then you can enable it from outside like:

 private TextOutPut$$anonymous$$anager TO$$anonymous$$;
 
 void Awake () 
     {
     //find the object where it is attached to
     TO$$anonymous$$ = GameObject.Find ("Game$$anonymous$$anager").GetComponent<TextOutPut$$anonymous$$anager> ();
     }
 
 void send()
 {
 //any condition then
 TO$$anonymous$$.inco$$anonymous$$g$$anonymous$$essage = "Blabla, show that message";
 TO$$anonymous$$.showtext = true;
 }


avatar image
0

Answer by Tekksin · Jul 26, 2018 at 07:33 AM

Generally, this error comes up when you start a coroutine that doesn't exist. Double check the name from that message variable.

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Can't start Coroutine since object is "Inactive" 1 Answer

Coroutine couldn't be started because the the game object 'Spawn' is inactive![SOLVED] 5 Answers

Code Executing Incorrectly in Update() 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