x


invoking an active coroutine

The documentation is a bit vague on this point, and I thought I'd ask on here before I went and blew my compiler up...

What happens when a coroutine is called which is already running?

e.g. say I have this code set up in a coroutine: (note: this requires other code to work, but it'll make the point)

IEnumerator basicIdea
{
  while(target!=null)
    {
    transform.rotation = Quaternion.Slerp(transform.rotation, rot, Time.deltaTime * turnSpeed);

    transform.position += transform.forward * speed * Time.deltaTime;
    }
  yield break;
}

what would happen if I had a function such as:

void CoroutineInvokation
{
startCoroutine(basicIdea);
}

...and the invoking function was in a position to be called again before the coroutine finishes?

would it be more appropriate to do something like this?:

   void CoroutineInvokation
    {
      stopCoroutine(basicIdea);
      startCoroutine(basicIdea);
    }

Basically what this comes down to is...will a new instance of a coroutine be created when it is called again or will it reset the existing one?

more ▼

asked May 27 '11 at 04:33 AM

digitalConundrum gravatar image

digitalConundrum
156 13 14 21

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

A new instance is created when it's called again.

more ▼

answered May 27 '11 at 04:42 AM

Eric5h5 gravatar image

Eric5h5
81.5k 42 133 529

wonderful, thank you; you just saved me hours of throwing profanities at my pc.

May 27 '11 at 04:44 AM digitalConundrum
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4368
x116
x63
x39

asked: May 27 '11 at 04:33 AM

Seen: 1363 times

Last Updated: May 27 '11 at 04:44 AM