Unity: Events and Event System

  Рет қаралды 44,250

Root Games

Root Games

Күн бұрын

Learn what events are and how to create Event Manager/System in this simple and beginner friendly tutorial .
✅ Get my courses with discount:
👉 Unity 2D Master: www.udemy.com/course/unity2dm...
👉 Unity Mobile Course: www.udemy.com/course/unitymob...
👉 Unity Input System with Rebinding: www.udemy.com/course/unity-in...
👍 Save your time and learn Unity faster
-------------------------------------------------------
🔔 Subscribe for more awesome content:
🔴 / @rootgames
-------------------------------------------------------
🟡 Support this channel through donations
Any amount means a lot and will help grow the channel:
👉 PayPal: www.paypal.com/paypalme/rootg...
-------------------------------------------------------
Social Networks:
⭐ Instagram: / rootgamesofficial
⭐ Twitter: / rootgamescro
⭐ TikTok: www.tiktok.com/@rootgamesoffi...
⭐ Facebook: / root-games-10337038860...
-------------------------------------------------------
0:00 Intro
0:14 Event System Structure
0:48 Simple Example
3:30 Open Doors
5:49 Tip- Static Class
6:22 Outro
#unitytutorial #events #eventsystem #unityevent #unity

Пікірлер: 77
@RootGames
@RootGames 2 жыл бұрын
✅ Get my courses with discount: 👉 Unity 2D Master: www.udemy.com/course/unity2dmaster/?couponCode=NEW-MASTER-MAY 👉 Unity Mobile Course: www.udemy.com/course/unitymobilecourse/?couponCode=MOBILE-MAY 👉 Unity Input System with Rebinding: www.udemy.com/course/unity-input-system-rebind/?couponCode=NEW-INPUT-MAY
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
Great video, very well explained, events are awesome!
@RootGames
@RootGames 2 жыл бұрын
Thanks so much! 😉
@pj-wille
@pj-wille 2 жыл бұрын
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!
@TheIronicRaven
@TheIronicRaven Жыл бұрын
I've watched tons of videos on events, and this is by far the simplest and easiest to follow!
@pawelpozoga
@pawelpozoga Жыл бұрын
What a clean example with no unnecessary code. Great explanation, as simple as it should be. Awesome!
@RootGames
@RootGames Жыл бұрын
Thanks, man. Always trying to keep it short and simple.
@chrismcpherson7582
@chrismcpherson7582 2 жыл бұрын
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 2 жыл бұрын
That's the point, thanks 😊
@Rommel89
@Rommel89 2 жыл бұрын
my shape is old and your shape is the new one used now?
@laur8233
@laur8233 2 жыл бұрын
Short and to the point. Love this kind of tutorials!
@NFS612
@NFS612 Жыл бұрын
Very nice tutorial. I'd recommend every beginner to watch this!
@user-cd1nr7zk9t
@user-cd1nr7zk9t Жыл бұрын
Plz do not delete this wonderful tutorial. So awesome !!
@RootGames
@RootGames Жыл бұрын
Don't worry 😉
@drinkwatrr9883
@drinkwatrr9883 2 жыл бұрын
Thank you so much, this was way more clear than any other tutorial and was short and to the point
@RootGames
@RootGames 2 жыл бұрын
Glad to help! :)
@Niter88
@Niter88 2 жыл бұрын
The best tutorial I've ever seen on the subject
@laude94wuo
@laude94wuo Жыл бұрын
Such a sharp explanation you have made. Thank you!!
@geoberry177
@geoberry177 Жыл бұрын
one of the only videos in the known universe that says "dont forget to unsubscribe"
@ep1417
@ep1417 Жыл бұрын
your explanation was very very helpful and thank you for that final tip, I found that very useful in my game. Thank you!
@blenderrenders7690
@blenderrenders7690 2 жыл бұрын
Very Nice! Quick, Easy to Understand, and a little quick tip at the end. Keep at it brother!
@RootGames
@RootGames 2 жыл бұрын
Thanks, will do! 😉
@FullShop2
@FullShop2 2 жыл бұрын
DAMN !!THIS IS A GREAT VIDEO! CONGRATS AND THANK YOU !
@pvsmouli7727
@pvsmouli7727 2 жыл бұрын
awesome video man. The explanation is very good. Thank you for the video & keep making more useful content like this
@MikaelL
@MikaelL Жыл бұрын
Thank you :)Thanks to your video I understood the Event System
@nnnxxx8921
@nnnxxx8921 2 жыл бұрын
Finally got the idea thanks a lot.
@RootGames
@RootGames 2 жыл бұрын
Most welcome, subscribe so you don't miss future tutorials 😊
@nnnxxx8921
@nnnxxx8921 2 жыл бұрын
@@RootGames as you wish ^^
@mastervolodsobeck5176
@mastervolodsobeck5176 Жыл бұрын
Great video, very well explained!
@arisaek7764
@arisaek7764 Жыл бұрын
Very helpful tut!
@TheSteveTheDragon
@TheSteveTheDragon 2 жыл бұрын
Really like how you lay things down so simply and easy to understand. Thank you so much!
@RootGames
@RootGames 2 жыл бұрын
Glad you like it! 😊
@allindoge
@allindoge 2 жыл бұрын
Thanks you, you explain this very well!
@RootGames
@RootGames 2 жыл бұрын
Glad it was helpful! 😊
@juancamiloangaritamateus5842
@juancamiloangaritamateus5842 6 ай бұрын
Amazing Video, Thank You so much
@RootGames
@RootGames 6 ай бұрын
Glad it was helpful!
@albertmon5712
@albertmon5712 Жыл бұрын
Awesome video! Thanks
@ramshyblood
@ramshyblood Жыл бұрын
nice video, I understood now
@user-fs1zf4eq4t
@user-fs1zf4eq4t 2 жыл бұрын
Great video too!
@swordandcasket5346
@swordandcasket5346 6 ай бұрын
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?
@othmanmoat
@othmanmoat 7 ай бұрын
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
@leonaxt611
@leonaxt611 Жыл бұрын
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.
@mertcaninam9359
@mertcaninam9359 11 ай бұрын
Great video, thank you
@RootGames
@RootGames 11 ай бұрын
Glad to help! 😉
@Medjack19
@Medjack19 2 жыл бұрын
Nice à Good tuto
@radioactivefrog55
@radioactivefrog55 Жыл бұрын
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?
@BrianLindahl
@BrianLindahl 2 жыл бұрын
Beautiful! Been having so much trouble understanding the logic and you explained it wonderfully!
@RootGames
@RootGames 2 жыл бұрын
Glad to help! :)
@Hamentsios10
@Hamentsios10 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 Жыл бұрын
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.
@pj-wille
@pj-wille 2 жыл бұрын
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.
@alfiandm5782
@alfiandm5782 Жыл бұрын
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 Жыл бұрын
i already assign my movepoint into thus script thoug
@alfiandm5782
@alfiandm5782 Жыл бұрын
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)
@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.
@moso3647
@moso3647 2 жыл бұрын
do you recommend events or interfaces?
@RootGames
@RootGames 2 жыл бұрын
Depending on what you need to do, but usually I prefer events.
@Astamor
@Astamor 2 жыл бұрын
I believe it's better practice to subscribe to events in OnEnable function instead of Start function.
@RootGames
@RootGames 2 жыл бұрын
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.
@alfonzo6320
@alfonzo6320 28 күн бұрын
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.
@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 жыл бұрын
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 🙂
@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?
@pixelpat5276
@pixelpat5276 11 ай бұрын
I think you left the letter 'r' out of the word 'EventManage' ? So it should be 'EventManager' instead?
@ashkelongonzaga6652
@ashkelongonzaga6652 2 жыл бұрын
why the game keep pausing when i hit a boxcollider2d
@RootGames
@RootGames 2 жыл бұрын
Check if you have “pause on error” option turned on. Maybe you have a null reference error or something.
@ashkelongonzaga6652
@ashkelongonzaga6652 2 жыл бұрын
@@RootGames ty it works now
@joaquinillo_
@joaquinillo_ 2 ай бұрын
Why are you not using delegates?
@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 жыл бұрын
Sorry, I don't understand you, only English.
@Rommel89
@Rommel89 2 жыл бұрын
(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 жыл бұрын
love your video, 1 sub from me, tks u
Unity: Camera follow with Cinemachine (2D)
5:35
Root Games
Рет қаралды 7 М.
The Power of Scriptable Objects as Middle-Men
17:41
samyam
Рет қаралды 116 М.
Why You Should Always Help Others ❤️
00:40
Alan Chikin Chow
Рет қаралды 10 МЛН
Eccentric clown jack #short #angel #clown
00:33
Super Beauty team
Рет қаралды 28 МЛН
ХОТЯ БЫ КИНОДА 2 - официальный фильм
1:35:34
ХОТЯ БЫ В КИНО
Рет қаралды 2,7 МЛН
ONE MORE SUBSCRIBER FOR 6 MILLION!
00:38
Horror Skunx
Рет қаралды 15 МЛН
Event Manager in Unity - Observer Pattern on Steroids !
14:08
NotJustUnity
Рет қаралды 7 М.
ULTIMATE Event System for Unity Beginners
8:27
This is GameDev
Рет қаралды 42 М.
SCRIPTABLE OBJECTS and EVENTS in Unity
6:46
Root Games
Рет қаралды 2,8 М.
(FREE COURSE) Make awesome CUTSCENES in Unity using Timeline
41:52
C# Events & Delegates
17:21
Tarodev
Рет қаралды 82 М.
Unity Architecture for Noobs - Game Structure
16:24
Tarodev
Рет қаралды 184 М.
How to Use Actions in Unity [Unity Tutorial]
14:49
Comp-3 Interactive
Рет қаралды 30 М.
The Unity Tutorial For Complete Beginners
46:39
Game Maker's Toolkit
Рет қаралды 3,1 МЛН
What are Events? (C# Basics)
15:05
Code Monkey
Рет қаралды 373 М.
Spare Your Pain Using UNITY EVENTS Tutorial
7:24
BMo
Рет қаралды 24 М.
Why You Should Always Help Others ❤️
00:40
Alan Chikin Chow
Рет қаралды 10 МЛН