MonoBehaviour Lifecycle Basics - Awake OnEnable Start Update FixedUpdate | Unity C# Basics Part 3




Published: 22 Mar 2022

Learn about the order of execution of events in Unity, or as I like to call it, the Component Lifecycle. This is critical to understand so you know with certainty when your Awake, Start, and Updates are being called! We'll even take a look at some examples of how you can get into trouble if you don't understand when they are called. To showcase these "lifecycle events" we'll also learn about how to create objects in the scene at runtime, and remove them!


If you've been using Unity for a while, or are just getting started with Unity and decided it's time for you to start learning how to write code - this is the video series you need to start your programming journey!


๐Ÿ‘จโ€๐Ÿ’ป As always, all code from this video is available on GitHub: https://github.com/llamacademy/unity-csharp-basics-3


๐Ÿท๏ธSave 25% on the ultimate C# IDE: JetBrains Rider with code LLAMACADEMY: https://www.jetbrains.com/store/?section=personal&billing=yearly


Full Series Playlist Here: https://www.youtube.com/watch?v=SXaa61JWLDw&list=PLllNmP7eq6TTjwoyfRYAAFOH1sMHVgI1r


โšซ Part 1 - Writing your first script - https://youtu.be/SXaa61JWLDw

โšซ Part 2 - Loops and Arrays - https://youtu.be/MB6B9nHSrps

โšซ Part 3 - Unity Component Lifecycle - https://youtu.be/TD3yoFg3GVI

โšซ Part 4 - Static vs Instances - https://youtu.be/JRRlAzBh-6U

โšซ Part 5 - Delegates - https://youtu.be/1N6k7Hj_JKc

โšซ Part 6 - Inheritance & Interfaces - https://youtu.be/siRvSZzrhRU

โšซ Part 7 - Compositional Relationships - https://youtu.be/khIweJfnyW4


By this point, you've probably already used some of these lifecycle events, but maybe didn't fully understand how they were called or when they were called. In this tutorial you'll learn the order of execution of the following events, and what type of code you should generally put in those events:

โšซ Awake

โšซ Start

โšซ OnEnable

โšซ FixedUpdate

โšซ Update


๐Ÿ“๐Ÿ“๐Ÿ“YOUR HOMEWORK!๐Ÿ“๐Ÿ“๐Ÿ“


Using the prefab we created and used today and at least 1 new script (maybe you need more, maybe not, you decide ๐Ÿ˜‰) make it where when the user left clicks in the top 10% of the screen, a new instance of our Count Down Text prefab is spawned at that left click location. Make the Count Down Text prefab start falling towards the bottom of the screen.


The Count Down Text should be destroyed under 2 conditions:

1. If the AutoDestroyText count down has reached 0.

2. If the Count Down Text has gone off screen (fallen out of view).


Here's some key resources for you to gather input from the user:

โšซ https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Mouse.html

โšซ https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/api/UnityEngine.InputSystem.Controls.ButtonControl.html


Add a comment below with a video showing your code and the end result.


๐Ÿ“š Here are the resources I mentioned and/or brought up during the video ๐Ÿ“š

โšซ Order of Execution: https://docs.unity3d.com/Manual/ExecutionOrder.html

โšซ GetComponent: https://docs.unity3d.com/ScriptReference/Component.GetComponent.html

โšซ Instantiate: https://docs.unity3d.com/ScriptReference/Object.Instantiate.html

โšซ Destroy: https://docs.unity3d.com/ScriptReference/Object.Destroy.html

โšซ Vector3s: https://docs.unity3d.com/ScriptReference/Vector3.html

โšซ Quaternions: https://docs.unity3d.com/ScriptReference/Quaternion.html

โšซ Screen: https://docs.unity3d.com/ScriptReference/Screen.html

โšซ Time: https://docs.unity3d.com/ScriptReference/Time.html


๐Ÿงก Believe in LlamAcademy's mission and have received value from the videos? Here's how you can show your support:

๐ŸŒŸ Patreon: https://www.patreon.com/llamacademy

๐ŸŒŸ YouTube Member: https://www.youtube.com/channel/UCnWm6pMD38R1E2vCAByGb6w/join or click the Join button on any video

๐Ÿ“š Take my Unity ShaderGraph Course:

https://www.gamedev.tv/p/unity-shader-graph?affcode=45216_kuvg0bp7

๐Ÿ‘• Get yourself some LlamAcademy merch: https://llamacademy.myspreadshop.com/

๐Ÿ’ธ Use my Affiliate Link for Humble Bundles https://humblebundleinc.sjv.io/9g4ak4

๐Ÿ’ธ Publisher Sale! 50% OFF an entire publisher's Assets! Publisher changes weekly! https://assetstore.unity.com/publisher-sale?aid=1101l9QvC (affiliate)

๐Ÿ’ธ Save up to 50% on NEW Assets: https://assetstore.unity.com/?new_sale=true&orderBy=1&aid=1101l9QvC (affiliate)


Some links may be affiliate links, which at no additional cost to you, gives me a small portion of the purchase.


Connect on Social Media

Some links may be affiliate links, which at no additional cost to you, gives LlamAcademy a small portion of the purchase.