Is StartCoroutine necessary to call from one subprogram to another joint program?

If you have nested shared procedures, for example

void Update()
{
    if(someTest)
    {
        StartCoroutine(Foo());
    }
}

IEnumerator Foo()
{
    doStuff = true;
    yield return StartCoroutine(Bar());
    doStuff = false;
}

IEnumerator Bar()
{
    //Very important things!
}

Is it required StartCoroutinein yield return StartCoroutine(Bar());?

Is it allowed to just do

void Update()
{
    if(someTest)
    {
        StartCoroutine(Foo());
    }
}

IEnumerator Foo()
{
    doStuff = true;
    yield return Bar();
    doStuff = false;
}

IEnumerator Bar()
{
    //Very important things!
}

If we are allowed, does this affect the behavior / performance of the program?

+4
source share
1 answer

Is StartCoroutine in yield return StartCoroutine (Bar ()); is it necessary?

No, you are allowed to use yield return Bar();.

If we are allowed, does this have any impact on program behavior / performance?

Yes, both in terms of behavior and performance.

Difference :

yield return StartCoroutine(coroutineFunction()):

(Bar)

: 56

: 2

yield return coroutineFunction():

(Bar)

: 32

: 3

, . for , yield return StartCoroutine(coroutineFunction()). , . , Time and Self ms Profiler , , yield return StartCoroutine(coroutineFunction()).

:

yielding i++ vs ++i (post pre increment). , yield return coroutineFunction(), .

+5

Source: https://habr.com/ru/post/1667170/


All Articles