Search Unity

Why Is better? StopCoroutine or Yield break?

Discussion in 'Scripting' started by QuanticFish, Oct 29, 2019.

  1. QuanticFish

    QuanticFish

    Joined:
    Apr 11, 2015
    Posts:
    2
    I am developing a mobile RPG game... I need to know which is better for performance... I think are same, or not??
    Code (CSharp):
    1. private IEnumerator countdownAttack()
    2. {
    3.    yield return WaitForSeconds(1f);
    4.    StopCoroutine (countdownAttack ());
    5. }
    6.  
    7. or
    8.  
    9. {
    10.     yield break;
    11. }
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    You could probably build some benchmark test and run it many times and see how your test candidates perform?
     
    Last edited: Oct 29, 2019
  3. QuanticFish

    QuanticFish

    Joined:
    Apr 11, 2015
    Posts:
    2
    Thanks... so, are the same? for stop any coroutine, as different methods for the same function?
     
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    The first one doesn't work, so I'd go with the second one! Also this is not a documentation question.