In Unity, I want to trigger an event when an audio clip finishes playing. Would it be more CPU efficient to keep checking if the audio clip is playing with

WaitUntil(() => audioSource.isPlaying == false);

or would it be more efficient to use:
to simply wait a certain amount of time?

How can I run a test in Unity to see which one is more CPU efficient?

  • \$\begingroup\$ Did you try starting a few hundred of one of these, to see if one version or the other makes a more noticeable spike in the profiler? \$\endgroup\$
    – DMGregory
    Mar 24 '19 at 20:43
  • \$\begingroup\$ No, how do I start a few hundred coroutine events at the same time that also run simultaneously? \$\endgroup\$ Mar 24 '19 at 20:44
  • \$\begingroup\$ The same ways we use to do a few hundred passes of most other things should work, like a standard for loop. What did you try? \$\endgroup\$
    – DMGregory
    Mar 24 '19 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.