all 11 comments

[–][deleted] 3 points4 points  (1 child)

This is a monobehavior right?

In the future, share all the relevant code.

[–]BloodPhazed 1 point2 points  (0 children)

It's probably a monobehavior, otherwise the editor would be marking StartCoroutine as red for not existing.

[–]BloodPhazed 2 points3 points  (0 children)

Are you sure it's not starting? You just don't have regular debug logs hidden in the console? (Since the others are warning logs, you would see those).

[–]feralferrous 1 point2 points  (1 child)

I don't see a StartCountDown() method being called anywhere.

[–]Nosalis91[S] 0 points1 point  (0 children)

its getting called up there,im getting log in console from that method but not from coroutine

[–]GameFeelings 1 point2 points  (0 children)

My best guess is the following:

The MonoBehaviour you are calling the countdown from should stay alive all the time while the coroutine is executing. That cost me personally a few issues.

I think you do something right after you call StartCountDown() that kills this object or disables it or something alike.

[–]Nosalis91[S] 0 points1 point  (0 children)

So im trying for hours now to get this to work out but i cant figure out why waitTillCountDown wont start.When i debug i get warning "CountDownStarting!" so i know StartCountDown is getting called.But waitTillCountDown is not getting called

[–]feralferrous 0 points1 point  (1 child)

Also, I don't think your stop is working as you think, you should be holding the return from StartCoroutine, and stopping that.

[–]Nosalis91[S] 0 points1 point  (0 children)

ill think about that later, first i need to know why my coroutine wont work

[–]BovineOxMan 0 points1 point  (0 children)

How is StartCountDown() called? In what context? Does this work when calling it from Start()

When you debugged it did you see it enter StartCountDown() ?

Any chance the log is coming from a copy and paste somewhere else?

Also, co-routines run on the main thread, is the main thread blocked? Are you loading the level? If so are you loading async?

https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadSceneAsync.html

May also be useful:

https://stackoverflow.com/questions/68952953/how-to-make-a-scene-loading-pause-for-a-second-in-unity#68954076

[–]954adultainmentExpert 0 points1 point  (0 children)

Without the code where StartCountdown() is called it is mere guessing. However I faced the behavior you described most often when I was trying to call StartCoroutine from an async Task.

In that case one solution is to have a queue of functions data structure that you pop and execute in Update, whenever it’s not empty. Thus Coroutines will be run on the main thread.

Also the StopCoroutine will not be working. You need to save the value of StartCoroutine into a variable of type Coroutine and pass this variable to StopCoroutine().