Coroutine missing hint and error

If i have a Coroutine IEnumerator ababa() there is no error or hint that something is wrong if i try to call the function ababa() without StartCoroutine(ababa())
I had to look for hours to find this mistake because i forgot to write StartCoroutine in front of it, maybe it would be nice to implement a message in c# for that.

There's no need for a warning or an error because calling that function is not an error. It returns the IEnumerator as promised. Unity has no idea you intend to use it as a coroutine. For all it knows you will enumerate it yourself.

You can write iterator functions that are not coroutines and it is perfectly valid:
https://docs.microsoft.com/en-us/dotnet/csharp/iterators#enumeration-sources-with-iterator-methods

2 Likes

This is so unnecessary. Use the beauty and power of instantly and immediately putting a Debug.Log() statement into the very start of the coroutine, right at the top.

Do this always at the very first sign of trouble or question in your mind.

The instant you did this you would see “Oh man, this code is simply not getting run!”

And you could LASER-FOCUS 100% your efforts on studying what you expect to run it, eg., the call location, and isolate why it is not running.

You would look at literally NOTHING else but that issue until your resolve that one issue.

With that focus, you could also refer to any other successful coroutine anywhere else on the planet and go “Oh, I’m missing the StartCoroutine() wrapper!”

7 Likes

[quote=“Kurt-Dekker”, post:3, topic: 839300]
This is so unnecessary. Use the beauty and power of instantly and immediately putting a Debug.Log() statement into the very start of the coroutine, right at the top.

Do this always at the very first sign of trouble or question in your mind.

The instant you did this you would see “Oh man, this code is simply not getting run!”

And you could LASER-FOCUS 100% your efforts on studying what you expect to run it, eg., the call location, and isolate why it is not running.

You would look at literally NOTHING else but that issue until your resolve that one issue.

With that focus, you could also refer to any other successful coroutine anywhere else on the planet and go “Oh, I’m missing the StartCoroutine() wrapper!”
[/quote]

This is very helpful thank you! I didnt even think to use Debug.Log(). I am going to try this out now.

1 Like

Je voudrais dire que si on clique sur un plan alors ne pas déplacer ce dernier .
Pour cela j'utilise le code suivant :

if (Input.GetMouseButtonDown(0))
        {
            Rayon = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit a frappé ;

            if (Physics.Raycast (ray, out hit))
            {
                planeComponent = hit.collider.GetComponent<Plane>();

                if (planeComponent != null)
                {
                    Debug.Log("Le rayon frappe un objet avec le composant Plane!");
                }
                else
                {
                    Debug.Log("Le rayon touche un objet qui n'a pas le composant Plan!");
                }
            }
        }

Le problème, c'est que le compilateur ne reconnait pas 'planeComponent'

Si vous avez des idées de codes,

Merci encore,

A+