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

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ก.ค. 2024
  • 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!
    💸 Ongoing sales 💸
    ⚫ See all active asset sales on the Asset Store: assetstore.unity.com/?on_sale...
    ⚫ Save 25% off your first Asset Store Order: prf.hn/click/camref:1101l9QvC...
    ⚫ Save up to 50% on NEW Assets: assetstore.unity.com/?new_sal...
    👨‍💻 As always, all code from this video is available on GitHub: github.com/llamacademy/unity-...
    ❤ Believe in LlamAcademy's mission and have received value from the videos? Become a Patreon Supporter or TH-cam Member:
    ⚫ Patreon: / llamacademy
    ⚫ TH-cam Member: / @llamacademy or click the Join button on any video
    Full Series Playlist Here: • Want to Start Writing ...
    ⚫ Part 1 - Writing your first script - • Want to Start Writing ...
    ⚫ Part 2 - Loops and Arrays - • Loops and Arrays | Uni...
    ⚫ Part 3 - Unity Component Lifecycle - • MonoBehaviour Lifecycl...
    ⚫ Part 4 - Static vs Instances - • Static vs Instances | ...
    ⚫ Part 5 - Delegates - • Delegates? Basically, ...
    ⚫ Part 6 - Inheritance & Interfaces - • Inheritance and Interf...
    ⚫ Part 7 - Compositional Relationships - • Compositional Relation...
    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:
    ⚫ docs.unity3d.com/Packages/com...
    ⚫ docs.unity3d.com/Packages/com...
    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: docs.unity3d.com/Manual/Execu...
    ⚫ GetComponent: docs.unity3d.com/ScriptRefere...
    ⚫ Instantiate: docs.unity3d.com/ScriptRefere...
    ⚫ Destroy: docs.unity3d.com/ScriptRefere...
    ⚫ Vector3s: docs.unity3d.com/ScriptRefere...
    ⚫ Quaternions: docs.unity3d.com/ScriptRefere...
    ⚫ Screen: docs.unity3d.com/ScriptRefere...
    ⚫ Time: docs.unity3d.com/ScriptRefere...
    ----
    Most tutorials come from knowledge gained making survival.llama.software Llama Survival - a top-down zombie survival shooter for Android and iOS.
    I also have some Unity Assets (affiliate link): assetstore.unity.com/publishe...
    Some links may be affiliate links, which at no additional cost to you, gives me a small portion of the purchase.
    #unitytutorial #tutorialtuesday #gamedev #tutorial #unity #llamacademy #gamedevelopment #learntocode
    Chapters:
    00:00 Order of Execution Overview
    04:15 Scene / Prefab Overview
    04:48 Using Awake
    07:45 Using OnEnable
    08:00 Using Update
    09:25 Add AutoDestroyText.cs to our Prefab
    10:00 Using Instantiate in Update & Fixed Update
    14:36 Adding ObjectSpawner
    15:28 Examining the Order of Execution when Creating new Objects
    16:45 Final Thoughts & Homework

ความคิดเห็น • 10

  • @jorbascrumps
    @jorbascrumps 2 ปีที่แล้ว +2

    Love that you've got beginner friendly content like this alongside more advanced topics and somehow keep the quality up. Nice work 💪

    • @LlamAcademy
      @LlamAcademy  2 ปีที่แล้ว +1

      Much appreciated! 💪

  • @durvids474
    @durvids474 2 ปีที่แล้ว +1

    Great stuff as always! Thanks for taking the time!

  • @DrunkenJanitor
    @DrunkenJanitor 2 ปีที่แล้ว +1

    Always Amazing Content, THanks!

    • @LlamAcademy
      @LlamAcademy  2 ปีที่แล้ว

      🙏 thank you! I appreciate it!

  • @coconutperson1985
    @coconutperson1985 11 หลายเดือนก่อน

    65 th like lol
    no really this guy is insane

  • @Chaserbeam1
    @Chaserbeam1 10 หลายเดือนก่อน

    I followed this, but at some point, 'text' became Null and caused an exception error. I did the void awake thing you said would make it not happen and I can't figure out why it's not working properly. (I'm calling my text textPro because seeing 'text' and 'Text' confused me. I didn't want to make an error due to ambiguity.):
    void Awake()
    {
    textPro = GetComponent();
    autoDestroyTime = 5f;
    }

    • @LlamAcademy
      @LlamAcademy  10 หลายเดือนก่อน

      The only reason I can think that it becomes null (if it worked at one point and stopped working) is if you made a script change and didn't exit and re-enter play mode. Whenever we assign references like this, they get lost when unity recompiles the code and tries to keep playing.

  • @Fas00
    @Fas00 ปีที่แล้ว

    Where can i find the text prefab?

    • @LlamAcademy
      @LlamAcademy  ปีที่แล้ว

      I think we created the text prefab in part 2 th-cam.com/video/MB6B9nHSrps/w-d-xo.html or, maybe but less likely, part 1: th-cam.com/video/SXaa61JWLDw/w-d-xo.html