ME FIRST GAMES
Menu

games for me and you

Unity Coroutines

6/9/2020

0 Comments

 
Picture
Coroutines allow you to execute a sequence of code over multiple frames and empower you to write procedural animations and events over time.
📌 A normal method call, will run and return immediately when finished.
📌 A coroutine method call, can run, pause, run more later, and run to completion in later frame updates. Coroutines always execute on the main unity thread.
📌 Coroutines are great for coding a sequence of events over time. e.g. Playing an end screen animation: fill progress bar, wait, fly coins to the top, wait, fade in buttons.
📌 Coroutines have performance overhead, so you don't want to be starting hundreds every frame. However, invoking them once or twice per UI screen gives you all the benefits without the performance hit.
📌 yield return null - Pauses the coroutine and starts execution again the next frame, right after the Update call.
📌 yield return WaitForEndOfFrame - Pauses the coroutine and starts execution once the camera and GUI's are rendered this frame.
📌 yield return new WaitForSeconds - Pauses the coroutine and starts execution after x amount of seconds has passed.
📌 A common mistake is to abuse Coroutines and use them everywhere in your game. I rarely use Coroutines for anything besides the occasional UI animation sequence.
📌 Alternatives to Coroutines are Unirx, Async Methods, DOTween, and State Machines.
📌 Coroutines have gotten a bad wrap due to misuse. But they're a powerful tool when you invoke them carefully in your codebase.

0 Comments



Leave a Reply.

    Picture
    Me First Games is an independent game studio dedicated to creating unique and bizarre video games.
    GAMES HERE

    Red Matter

    Star Impact is an upcoming adventure platformer coming to PC, Mac, and Linux.

    Archives

    April 2021
    February 2021
    December 2020
    November 2020
    October 2020
    September 2020
    August 2020
    July 2020
    June 2020
    May 2020
    April 2019
    March 2019
    December 2018
    April 2018

    Categories

    All

    RSS Feed

Copyright (c) 2020 Me First LLC
  • STU the First AI
  • Blog
  • Contact
  • Unity Tools
    • Hierarchy Comments
  • STU the First AI
  • Blog
  • Contact
  • Unity Tools
    • Hierarchy Comments