Start vs Awake vs OnEnable (Unity Tutorial)

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 มิ.ย. 2024
  • In this Unity tutorial we're going to look at the differences between the Start, Awake, and OnEnable methods.
    The project files are available to our patrons here:
    ► / 62287013
    Help support our work:
    ► Patreon: / ketragames
    ► Ko-fi: ko-fi.com/ketragames
    Follow us:
    ► Ketra Games: www.ketra-games.com
    ► Patreon: / ketragames
    ► Twitter: / ketragames
    ► Facebook: / ketragames
    Introduction - 0:00
    Awake Method Overview - 0:19
    Start Method Overview - 0:43
    OnEnable Method Overview - 1:06
    Examples - 1:34
    Summary - 4:54
    #KetraGames #LearnUnity #UnityTutorials #UnityTips

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

  • @sibasisrath6774
    @sibasisrath6774 3 หลายเดือนก่อน

    Crisp, short and sweet explanation. Thank you for the demonstration and example.

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

    More videos like this please! Too often I feel like all I'm doing when I follow a tutorial is just copying what the video says without really learning anything. Stuff like this is so helpful for understanding how and why things are done the way they're done. Thank you!

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

      Excellent, great to hear 😊

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

    This is huge. I've always wondered about this but haven't seen any content explaining it.

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

      Thanks for this. Glad it was useful 😊

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

    Ketra Games are the best tutorials!

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

      Thanks for this comment 😊

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

    Thanks for the tutorial!
    I've recently been enjoying your Platformer tutorials as well. Really appreciate the time and effort you put into them.

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

      Great, thank you 😊

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

    perfect timing, i needed this and i didnt know i did! thank you

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

      Great to hear 😊

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

    Thanks!

  • @pneuma-studios2036
    @pneuma-studios2036 2 ปีที่แล้ว +3

    These three methodes are extremly usefull once you know how and when to use them ^^

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

    This tutorial is awesome! Thank you☺

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

      Thanks for this comment 😊

  • @ani-gamer320
    @ani-gamer320 2 ปีที่แล้ว +3

    Op 🔥❤️❤️

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

    Very useful! Thank you! :D

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

      Glad you found it helpful 😊

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

    ¡Gracias!

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

    Nice showcase!
    There is a handy flowchart on event functions I think every Unity dev shoud be aware of (for people reading this - the Execution Order of Event Functions):
    docs.unity3d.com/Manual/ExecutionOrder.html
    It's also possible to adjust the oder in which the same event methods are called for each object by using a specific script execution order. i'm not sure if there are methods that are excempt from this functionality though:
    docs.unity3d.com/Manual/class-MonoManager.html
    + there is an attribute that can be used above the MonoBehaviour class definition to set up a standard execution order for the Behaviour: [DefaultExecutionOrder(x)] with x being the execution order priority - lower values are called earlier, higher values later
    I think it's not uncommon to implictly have dependecies where one Start method needs to be called before the other one to avoid errors, and sometimes the order in which the start methods are called is correct in the editor. But there is no guarantee and I think it might be different in builds. So setting up references and calling methods in the right event methods is definitely important. Awake for initialization for all the data/references of the own object and Start to gather references and run logic on other objects for example.

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

      Thanks for sharing this 😊

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

    pls make a video how to make inventory...thx 😁😁

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

    ❤❤❤

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

    I was always wondering what is the best place to setup listening to other scripts' events ( "SomeClass.OnSomeEvent += HandleSomeEvent"). I usually assume, that classes can actually "do" stuff - like calling an event - as early as the Start()-Method. Therefore it makes sense to me, to make other Classes start listen to events in either their Awake() oder OnEnable() methods. Is there any particular advantage of using one over the other? What would be your recommendation?

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

      Hi, good question. If your objects can be enabled and disabled during the lifetime of the game then I'd recommend subscribing to the events in OnEnable and unsubscribing in OnDisable. That way you won't be handling the events when the object is disabled.