- Home /
StartCoroutine not working.
Hi, I am trying to add something like loading screen on start to show my logo and let game load files. But for some reason my coroutine doesn't start. Now I looked over this 20x times and I still don't see what is wrong with this code.
void Start()
{
....
StartCoroutine(HideLoadingScreen());
}
and
IEnumerator HideLoadingScreen()
{
print("started counting");
yield return new WaitForSeconds(3);
LoadingScreen.SetActive(false);
print("finished counting");
}
Why is this happening? What is wrong with this code
Answer by Bunny83 · Aug 01, 2016 at 01:53 PM
I don't see any reason why this shouldn't work, considering the information you provided. What exactly represents the "...." in Start? Could it be that you receive any errors in the console? Do you destroy the gameobject anywhere? Do you load a different scene somewhere? Maybe you have an early-exit statement somewhere before your StartCoroutine call? Any of those actions would prevent the coroutine from completing / executing.
Do you actually get any of your prints in the console? If not any errors?
Have you tried adding a pring / Debug.Log right before you call StartCoroutine?
If that doesn't print as well make sure your gameobject is active (the checkbox at the top left in the inspector)
Also make sure your script component is enabled (the checkbox at the top left of your script component.)
Keep in mind that other script could interfere with your script. Maybe another script somewhere changes the level or destroys your gameobject?
See Skurlexx's answer below
StartCoroutine("HideLoadingScreen");
In OP's code, the output of the method HideLoadingScreen() would be passed into StartCoroutine, not the name of the method to start
Answer by danivdwerf · Jul 29, 2016 at 07:49 PM
do you have
using System.Collections;
at the top of your code?
Also, is the script assigned to something??
goodluck man
Yes, and yes. Still no idea why it's not working. Everything is as it should be. Ps. Sorry for late response
Answer by CaptainIsolation · Mar 10 at 08:00 PM
Not likely for everyone, but my issue was because I had an overload of the method without a parameter.
IEnumerator sameMethodName(string value){
...
}
void sameMethodName(){
...
}
Renaming the method I didn't want fixed the problem
Your answer
Follow this Question
Related Questions
Invoke a Coroutine From OnCollisionEnter 1 Answer
C# change light color every few seconds 3 Answers
understanding coroutines 0 Answers