Unity: Events and Event System

Поделиться
HTML-код
  • Опубликовано: 15 ноя 2024

Комментарии • 79

  • @RootGames
    @RootGames  2 года назад +3

    ✅ Get my courses with discount:
    👉 Unity 2D Master: www.udemy.com/course/unity2dmaster/?couponCode=2D-MASTER
    👉 Unity Mobile Course: www.udemy.com/course/unitymobilecourse/?couponCode=MOBILE
    👉 Unity Input System with Rebinding: www.udemy.com/course/unity-input-system-rebind/?couponCode=UNITY-INPUT

  • @TheIronicRaven
    @TheIronicRaven 2 года назад +8

    I've watched tons of videos on events, and this is by far the simplest and easiest to follow!

  • @pawelpozoga
    @pawelpozoga Год назад +5

    What a clean example with no unnecessary code. Great explanation, as simple as it should be. Awesome!

    • @RootGames
      @RootGames  Год назад +1

      Thanks, man. Always trying to keep it short and simple.

  • @GoblinArmyInYourWalls
    @GoblinArmyInYourWalls 3 года назад +15

    Very straightforward! You describe exactly what the goal is and then outline it using limited code
    You speak clearly and say only as much as necessary for teaching.
    Thank you, very good tutorial

    • @RootGames
      @RootGames  3 года назад +2

      That's the point, thanks 😊

    • @Rommel89
      @Rommel89 2 года назад

      my shape is old and your shape is the new one used now?

  • @CodeMonkeyUnity
    @CodeMonkeyUnity 2 года назад +58

    Great video, very well explained, events are awesome!

    • @RootGames
      @RootGames  2 года назад +4

      Thanks so much! 😉

    • @pj-wille
      @pj-wille 2 года назад +3

      Oh man I literally just came from one of your videos where you used event's and I wanted to learn more.
      Thank you Root Games for this very good and concise tutorial!

  • @목이안
    @목이안 2 года назад +3

    Plz do not delete this wonderful tutorial. So awesome !!

  • @NFS612
    @NFS612 Год назад +2

    Very nice tutorial. I'd recommend every beginner to watch this!

  • @laur8233
    @laur8233 2 года назад +2

    Short and to the point. Love this kind of tutorials!

  • @geoberry177
    @geoberry177 Год назад +1

    one of the only videos in the known universe that says "dont forget to unsubscribe"

  • @Niter88
    @Niter88 2 года назад +1

    The best tutorial I've ever seen on the subject

  • @drinkwatrr9883
    @drinkwatrr9883 2 года назад +2

    Thank you so much, this was way more clear than any other tutorial and was short and to the point

  • @ep1417
    @ep1417 Год назад +1

    your explanation was very very helpful and thank you for that final tip, I found that very useful in my game. Thank you!

  • @TheSteveTheDragon
    @TheSteveTheDragon 3 года назад +4

    Really like how you lay things down so simply and easy to understand. Thank you so much!

    • @RootGames
      @RootGames  3 года назад

      Glad you like it! 😊

  • @othmanmoat
    @othmanmoat Год назад +1

    Hello, what is the advantage of having a static EventManager (the singleton pattern) instead of the first method which is shown?
    Anyway thank you for the video, it's going to clean my code a lot I think

  • @laude94wuo
    @laude94wuo 2 года назад +2

    Such a sharp explanation you have made. Thank you!!

  • @nnnxxx8921
    @nnnxxx8921 3 года назад +4

    Finally got the idea thanks a lot.

    • @RootGames
      @RootGames  3 года назад

      Most welcome, subscribe so you don't miss future tutorials 😊

    • @nnnxxx8921
      @nnnxxx8921 3 года назад +1

      @@RootGames as you wish ^^

  • @Hamentsios10
    @Hamentsios10 2 года назад +2

    Thanks for this very useful tutorial. One thing I don't fully get, is how the EventManager can be used/defined in other scripts. Is it because of the static? What makes its event data accessible from other objects and their scripts?

    • @RootGames
      @RootGames  2 года назад

      That's correct. You can easily use EventManager in other scripts because it's static (saved in the memory)

    • @marorerimeraremaro2533
      @marorerimeraremaro2533 2 года назад +1

      The "static" keyword marks data that belongs to an entire class and not an object created by that class. That means you can access these methods, variables etc. (the ones marked as "static") simply by typing "ClassName.ThingInClassYouWant".
      Another example that might help is, when you want to find the square root of a number, the code you type is "Mathf.Sqrt(number)". Mathf is a class and Sqrt() is a static function in that class. You don't need to create an object of class Mathf and then call the Sqrt() function on it.
      I hope that helps.

  • @nickvlahos4547
    @nickvlahos4547 Месяц назад +1

    Hey! This was pretty good! Thank you! :D

  • @juancamiloangaritamateus5842
    @juancamiloangaritamateus5842 Год назад +1

    Amazing Video, Thank You so much

  • @MikaelL
    @MikaelL 2 года назад +1

    Thank you :)Thanks to your video I understood the Event System

  • @radioactivefrog55
    @radioactivefrog55 Год назад +1

    i was hoping my event system could get a reference to my player and send that reference to whatever script needed it. is that possible?

  • @swordandcasket5346
    @swordandcasket5346 11 месяцев назад

    Now, do I need to to make that event manager static as well for reloading the scene mid-game or will this clean up on it's own?

  • @blenderrenders7690
    @blenderrenders7690 3 года назад +1

    Very Nice! Quick, Easy to Understand, and a little quick tip at the end. Keep at it brother!

    • @RootGames
      @RootGames  3 года назад +2

      Thanks, will do! 😉

  • @mastervolodsobeck5176
    @mastervolodsobeck5176 Год назад +2

    Great video, very well explained!

  • @BrianLindahl
    @BrianLindahl 3 года назад +2

    Beautiful! Been having so much trouble understanding the logic and you explained it wonderfully!

  • @FullShop2
    @FullShop2 2 года назад +1

    DAMN !!THIS IS A GREAT VIDEO! CONGRATS AND THANK YOU !

  • @pvsmouli7727
    @pvsmouli7727 2 года назад +1

    awesome video man. The explanation is very good. Thank you for the video & keep making more useful content like this

  • @arisaek7764
    @arisaek7764 2 года назад +1

    Very helpful tut!

  • @mertcaninam9359
    @mertcaninam9359 Год назад +1

    Great video, thank you

  • @神烦狗
    @神烦狗 2 года назад +2

    Thanks you, you explain this very well!

    • @RootGames
      @RootGames  2 года назад

      Glad it was helpful! 😊

  • @ramshyblood
    @ramshyblood 2 года назад +1

    nice video, I understood now

  • @pj-wille
    @pj-wille 2 года назад +1

    For the last part, is there a particular reason you might want to do it in Singleton style with an instance over the way you were doing it before?

    • @RootGames
      @RootGames  2 года назад

      Not really, it depends on what you need for your project. But I like to have a centralized singleton manager that will be responsible for most of the events.

  • @leonaxt611
    @leonaxt611 2 года назад

    Thank you so much for this! I'm just beginning unity but this is a great help. I do have a question. The only error I'm getting out of this is for the Door script.
    Within the Start method I have:
    EventManager.StartDoorOpen += OpenDoor;
    It wants me to place a variable for EventManager.StartDoorOpen().
    And I cannot place variable for either trigger ID or doorID because Unity has the error,
    [13:11:34] Assets/Door.cs(16,9): error CS1656: Cannot assign to 'StarDoorOpen' because it is a 'method group'.
    And another error the same but with:
    Assets/Door.cs(45,9)
    Any help of what I'm missing. Besides the action of the doors and some variable names I've followed suit on everything before you transition to singletons.

  • @albertmon5712
    @albertmon5712 2 года назад +1

    Awesome video! Thanks

  • @alfonzo6320
    @alfonzo6320 6 месяцев назад

    WARNING:
    if the object is disabled, the event wont trigger because the update is not executing. so there is absolutely no need to bother removing/adding the event action.
    SPECIALLY IF YOU DONT REGISTER THE ACTION "ONENABLE" BUT ONLY "ONSTART" LIKE THE VIDEO SHOW YOU.
    It wont be added back when you re enable the script... A really nasty mistake...
    What i would suggest instead register/unregister elements, just make sure the event wont happen on the action side instead. Event will still be triggered on every target, but each target will have the responsibility to handle weather they should responds or not to that trigger. ( Eg locked door vs unlocked one (if locked then don't trigger event). no need for premature optimisations if you only have 2-3 actions.

  • @徐茂源-z6g
    @徐茂源-z6g 2 года назад +1

    Great video too!

  • @moso3647
    @moso3647 3 года назад

    do you recommend events or interfaces?

    • @RootGames
      @RootGames  3 года назад

      Depending on what you need to do, but usually I prefer events.

  • @ryanoconnor7957
    @ryanoconnor7957 Год назад

    It's fine but honestly I think Unity's IEventSystemHandler is better than what you showed here because it is a 100% decoupled way of doing the observer pattern.

  • @alfiandm5782
    @alfiandm5782 2 года назад

    may i know what is the component inside MovePoint is it only object on where door goes (Transform)? i got a problem The variable movePoint of Door has not been assigned.
    You probably need to assign the movePoint variable of the Door script in the inspector.
    UnityEngine.Transform.get_position () (at :0)
    Door.Update () (at Assets/Door.cs:20)

    • @alfiandm5782
      @alfiandm5782 2 года назад

      i already assign my movepoint into thus script thoug

    • @alfiandm5782
      @alfiandm5782 2 года назад

      nvm i have solved my problem. it was because i got DoorParent That havent been attached by movePoint. i thoug we just need to attach it on child only (Door)

  • @Astamor
    @Astamor 3 года назад

    I believe it's better practice to subscribe to events in OnEnable function instead of Start function.

    • @RootGames
      @RootGames  3 года назад +1

      It depends on the situation and what you need. Actually, in this example, it will give you a null reference error if you subscribe in OnEnable function. Subscribe anywhere as long as it works.

  • @Medjack19
    @Medjack19 2 года назад +1

    Nice à Good tuto

  • @mani_mincraft
    @mani_mincraft Год назад

    Hi, when i try to type EventManager it gives me an error "The name 'EventManage' does not exist in the current context" any help?

    • @pixelpat777
      @pixelpat777 Год назад

      I think you left the letter 'r' out of the word 'EventManage' ? So it should be 'EventManager' instead?

  • @ashkelongonzaga6652
    @ashkelongonzaga6652 2 года назад +1

    why the game keep pausing when i hit a boxcollider2d

    • @RootGames
      @RootGames  2 года назад +2

      Check if you have “pause on error” option turned on. Maybe you have a null reference error or something.

    • @ashkelongonzaga6652
      @ashkelongonzaga6652 2 года назад +3

      @@RootGames ty it works now

  • @joaquinillo_
    @joaquinillo_ 7 месяцев назад

    Why are you not using delegates?

  • @arturwraga1831
    @arturwraga1831 2 года назад

    But i still do not get why should i use it instead of normal prefab of the door with triger? I that case de Player does not schare any data with the door.... Only check if the object in the tiger is a Player...

    • @RootGames
      @RootGames  2 года назад +1

      I will try to explain it more. Let's use the door example. Let's say you want to open the door and do one or more things at the same time. For example, open the door and zoom in the camera. In your case with prefabs, every prefab now has to have reference to the camera. It's better to just subscribe the camera to the event and in that case, in some levels/places when you open the door, you can, but don't have to use the camera feature. The code will work fine in either case. Then imagine you also want to enable some UI or play a specific sound that is played only with specific doors. Putting all that in prefabs and making references is a mess. Also, you can use events when picking up gems, for health bars and other stuff, your player doesn't have to store a reference to the UI. Hope it helps 🙂

  • @spirit-io7jf
    @spirit-io7jf Год назад

    Observer pattern

  • @hobbyblog8270
    @hobbyblog8270 Год назад

    What is the meaning of ?, when you are used in ExampleEvent?.invoke();

    • @RootGames
      @RootGames  Год назад

      It's a short version of the "if" statement. Just syntax.

  • @Rommel89
    @Rommel89 2 года назад

    yo me los aprendi asi
    Clase Jugador
    public delegate Mievento evento;
    public static Mievento evento(bool abrir)
    piblic void perdioVida()
    {
    Invoke?.evento( true );
    }
    CClase dibujarVida
    private void dibujarVida( bool quitarVida ){
    if( quitarVida == true)
    {
    //quita la vida y que se vea en la interfaz grafica
    }
    }
    public OnEnable(){
    Jugador.evento+= dibujarVida;
    }
    y ya lo que tu haces en las otras clase
    suscribirse y llamar al metodo
    algo asi me lo public delegate Mievento evento;
    public static Mievento evento(bool abrir) es viejo esta forma de hacerlo?

    • @RootGames
      @RootGames  2 года назад +1

      Sorry, I don't understand you, only English.

    • @Rommel89
      @Rommel89 2 года назад +1

      (Me)
      public delegate Mievento evento;
      public static Mievento evento(bool abrir) (old form, old method)
      (Your) public static Action evento (new form, new method)

  • @CCvodoi
    @CCvodoi 2 года назад +1

    love your video, 1 sub from me, tks u