What are Events? (C# Basics)

  Рет қаралды 405,315

Code Monkey

Code Monkey

Күн бұрын

Пікірлер: 670
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
🌍 FREE C# Beginner Complete Course! kzbin.info/www/bejne/poPIg2mQbtd-Y9E 🔴 Watch my Complete FREE Game Dev Course! 🌍 kzbin.info/www/bejne/d56qhHh-bLaWesk 📝 C# Basics to Advanced Playlist kzbin.info/aero/PLzDRvYVwl53t2GGC4rV_AmH7vSvSqjVmz 🌐 Have you found the videos Helpful and Valuable? ❤️ Get my Courses unitycodemonkey.com/courses or my Steam Games 🎮 unitycodemonkey.com/gamebundle Here's the highly requested C# Events video! This is one of the most important things to know about C# in order to keep your code nice and clean. 🎮 Play 7 Awesome Games (Action, Strategy, Management) and Help Support the Channel! ✅ Get the Game Bundle 67% off unitycodemonkey.com/gameBundle.php
@dragonlord1935
@dragonlord1935 4 жыл бұрын
Hey, Love your videos! I was wondering could you someday make a complete C# course? You're one of the few people online who use a consistent coding "style" which makes everything easy to follow. I'd love to see an in depth C# series made by you.
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
@@dragonlord1935 Yup a complete C# course is definitely something I'd like to do, just need to find the time.
@waterfan3399
@waterfan3399 4 жыл бұрын
@@CodeMonkeyUnity make it soon man...please
@RonnieBanerjee007
@RonnieBanerjee007 4 жыл бұрын
I have a question: As per my understanding of the unity engine, whatever happens in the 'update' function is executed every frame, then how does the Debug.log print "Space!" Whenever OnSpacePressed is invoked Even though the Debug.log doesn't stay in the update() !?
@lianefernando6041
@lianefernando6041 4 жыл бұрын
Do you have a tutorial where I can learn to use Test Driven Development approach in Unity?
@WagnerGFX
@WagnerGFX 4 жыл бұрын
Important: when using most (if not all) of the events described in the video is very important to unsubscribe from them when the listener is destroyed, since this could result in errors when calling events with dead listeners. A video on delegates would be awesome. You could also talk about the differences between Strong and Weak references.
@judgegroovyman
@judgegroovyman 4 жыл бұрын
Wagner Ferreira good point and for anyone who doesn’t know one good place to do that in Unity is creating a void OnDestroy() and put all of the unsubs in there
@danielcorzo7498
@danielcorzo7498 4 жыл бұрын
@@judgegroovyman I've also seen that a good practice is to put the unsubs in OnDisable() as calling an event with disabled listeners may also lead to errors. If I'm not wrong, when an object is destroyed OnDisable() is called too.
@judgegroovyman
@judgegroovyman 4 жыл бұрын
Daniel Corzo that sounds even better than my suggestion!
@WagnerGFX
@WagnerGFX 3 жыл бұрын
The GC removes the object that was listening to the event, but not the registered listener itself, so when the event is fired the listener will be pointing to an invalid reference and throws an error. This is where using weak references is useful, but it is usually heavier since the event handler must check every listener for nulls before firing any events.
@mwwhited
@mwwhited 2 жыл бұрын
@@WagnerGFX And if you have multiple subscribers with multicastdelegates it can get even more grumping especially if someone decides to use an `async void` handler. Also when the GC does a mark and sweep if you aren't using a weak reference it will keep the subscriber event after all other objects are dereferenced leaving you with a resource leaks. There are really a lot of issues with the fundamentals of the events in .Net. It would be better if people used different patterns for decoupling.
@Synith19
@Synith19 3 жыл бұрын
The code shown at 10:14 should not allow "Space! 2" to "Space! 5" to show in the console at 10:23 as he is unsubscribing from the event as soon as he fires it. Just wanted to clarify in case anyone else gets stuck wondering how he was able to fire off the event multiple times, I believe it was an editing error. If you remove the unsubscribe it will work as he is showing.
@diyguild1327
@diyguild1327 3 жыл бұрын
Thank you this was confusing to me as well
@loucollinsZEN
@loucollinsZEN 2 жыл бұрын
Thanks
@Aye_Sid
@Aye_Sid 2 жыл бұрын
Thanks bro. 😀👍🏻
@yujiashan
@yujiashan 11 ай бұрын
Thank you!
@LeMonkeyLe
@LeMonkeyLe 10 ай бұрын
OMG i was loosing my mind over it Repeatedly checking the script if i made any errors in it Thank you Very much
@ganaraminukshuk0
@ganaraminukshuk0 4 жыл бұрын
If a tree falls in a forest, the event system doesn't care if anyone was listening if at all.
@gadgetboyplaysmc
@gadgetboyplaysmc 4 жыл бұрын
k
@deadturret4049
@deadturret4049 4 жыл бұрын
this is an oddly useful way of wording that information.
@matshalvarsson8878
@matshalvarsson8878 3 жыл бұрын
public class ForestManager { public event EventHandler OnTreeFall; private void Update() { if (Input.GetTreeDown(TreeCode.Timbeeeeerrr)) { OnTreeFall?.Invoke(this, EventArgs.WatchOut); } } } public class ForestHikerAndPartTimePhilosopher { private bool isOutOnAHike; private void Start() { ForestManager universePhysics = FindManager(); universePhysics.OnTreeFall += TheUltimateQuestionAboutReality; } private void TheUltimateQuestionAboutReality(object physics, EventArgs e) { if (isOutOnAHike) { Debug.Log("A tree fell in the forest and a hiker is there, so he could hear the tree fall."); } else { Debug.Log("A tree fell in the forest, but the hiker was not there, so he couldn't hear the tree fall. Did it make a sound?"); } } }
@ShootYourBricks
@ShootYourBricks 3 жыл бұрын
@@matshalvarsson8878 Looks like someone is procrastinating their real project XD
@matshalvarsson8878
@matshalvarsson8878 3 жыл бұрын
@@ShootYourBricks hahaha!
@calebforbes9169
@calebforbes9169 2 жыл бұрын
Thank you for showing it in action with multiple examples, but without extra confusion!
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
I'm glad you found that helpful! Thanks!
@nicolapatti3733
@nicolapatti3733 4 жыл бұрын
The shortest and clarifying video about events I've ever seen since now! Thank you.
@erz3030
@erz3030 4 жыл бұрын
I love these nuts and bolts tutorials you're now doing (in addition to everything else you do lol). You're such an excellent and thorough teacher. Your examples are so concrete and easy to follow.
@bananenkris
@bananenkris 3 жыл бұрын
These nuts.
@AGZF1983
@AGZF1983 3 ай бұрын
@@bananenkris thats an old joke, a very old joke.
@zerotoanime3953
@zerotoanime3953 2 жыл бұрын
This is single-handedly the best video on youtube about events. Thank you so much.
@hasnainfareed8555
@hasnainfareed8555 2 жыл бұрын
I swear I want to like it for 100 times, Your teaching method is remarkable.Thank You SOOOO much. You are a legend
@ronnid8837
@ronnid8837 4 жыл бұрын
Damn.. I nearly searched the whole web on events/delegates, but your tutorial was the only one which made it clear for me! Awesome explanation and practical use cases. You got a new subscriber =D
@Analogity
@Analogity 4 жыл бұрын
I've said it once but I'll say it again... THANK YOU! I'm a professional dev but new to game development, and these are the magic tutorials I have been looking for. I absolutely love your approach to teaching and your commitment to proper design. Thanks for the utils as well! I subscribed on Patreon and am excited to follow all the amazing content you put out. Seriously, absolutely amazing tutorials. I've shared with all my friends! :)
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Thanks! Glad you like them!
@Runix1
@Runix1 2 жыл бұрын
I think this is the sixth time I've returned to this video. It's such a great resource, both for usecases and syntax.
@hubbubbobbin
@hubbubbobbin 10 ай бұрын
I was doing the unity KitchenChaos Course and came here for a little more help because I felt like I couldn't do this on scratch from my own. But after this video I feel like I completely grasp it and create an event system from scratch, so I can move on! Thank you for your videos!
@CodeMonkeyUnity
@CodeMonkeyUnity 10 ай бұрын
Nice! Great job on going deeper on a specific topic!
@opt4623
@opt4623 9 ай бұрын
Same. I stopped at this point and came here for more clarification before I move on with the course! Sadly I am still struggling to grasp the concept :3
@JonathanGilmer
@JonathanGilmer Ай бұрын
​@opt4623 don't worry, you're not alone! I watched it twice before it really started to stick.
@manuelgarciacamacho106
@manuelgarciacamacho106 29 күн бұрын
Same here. Not surrender!!
@roygatz
@roygatz Жыл бұрын
This is really the essential part to build a game. This should deserve more attention. Great job done!
@0fficez0mbie
@0fficez0mbie 2 жыл бұрын
Thank you so much for these tutorials! The way you start with basic examples and then gradually layer up the additional functionality has really helped my understanding of the underlying concepts (and meant that I can apply the learning confidently!).
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
I'm glad they've helped you! Thanks!
@foreducation408
@foreducation408 2 жыл бұрын
after learning about the delegates, learning about the events is pretty easy and as always your videos are the best for in-depth knowledge.
@MrCrompz
@MrCrompz Жыл бұрын
I watched multiple videos to try and understand events, but as usual, yours was the best and the one which actually helped me understand them! Thanks!
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
I'm glad the video helped! Events are insanely useful so I'm sure they'll help you a lot in your game dev journey!
@Andrew90046zero
@Andrew90046zero 4 жыл бұрын
Ever since I saw you using C# events a while back instead of UnityEvents, I decided to look into c# events. Now I have decided that's what I'm gonna use for now on. And yea you should definitely do a tutorial on all that function variable goodness. You should talk about: * delegates * Func, Action, Predicate premade delegates * and how they can be used in a bunch of different ways like passing functions as parameters to another function. And also the idea of callbacks. * Lambda functions * Local Functions (these are actually kinda cool, idk if you ever used them but they are a nice alternative to lambda functions) A really good example I know of for demonstrating Function variables would be the "Calculus Summation Function". Where you have to pass it 3 values: starting integer, summation size, and a function to apply the summation to. And the user can pass in any function they want like f(x) = x^2 and the summation would be like 1^2 + 2^2 + 3^2 + ... + n^2
@JohnnySix
@JohnnySix 4 жыл бұрын
This is awesome - I remember Unreal Engine having something similar ( back in UT99 ) - this is way more efficient than having scripts reference / check public variables / functions in other scripts. Bonus points for the new C# 6 null-conditional operator - that's super useful too. :)
@themirlabs
@themirlabs 3 жыл бұрын
Every now and then i need to use events again and i return here every time. Thanks for these videos
@davdev793
@davdev793 4 жыл бұрын
Thats gold, growing more interest every day on your channel! I was using a custom messaging system that i've learned to code in a very old unity book, probably from before event's support arrive in unity. It is basically a much more complex way to do what you do with events. I tried the unity courses on this before but your explanation is just clean and easy to understand. Adapting my projects now. Thanks!
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
I'm guessing you were using SendMessage(); which is one possible approach but it's not very good since it's very much based on strings which can easily break your code and causes terrible performance.
@d3monskils386
@d3monskils386 2 жыл бұрын
I know it's an old video but i find si relaxing to listen and hear the keyboard sound in the back ! Thanks for those tutorial.
@kstevenson3504
@kstevenson3504 Жыл бұрын
So many videos make this complicated. (Some additional syntax might be helpful for those of us who see examples in ohter syntax, but this is so simple and easy to understand.) You made this seem way too easy. SMH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! I've watched so many videos that try to take you through the event/delegate encyclopedia! Its overwhelming. I'm so refreshed. Thanks!
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
I'm glad the video helped you! Events are one of the most powerful C# features!
@Rahulsingh-theraha
@Rahulsingh-theraha 2 жыл бұрын
revised both delegate and events and it was really good ,thank you for ur explanation
@BrunevaStudios
@BrunevaStudios 4 жыл бұрын
Man, watching this video made me realize I need some actual basic coding lessons, as it was very hard for me to follow the video. Not because of what was shown, the video itself is very well presented and the subject is taught well. Thanks for all of your videos, they really do help out an aspiring game dev!
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Interesting, what part/concept did you have trouble following? Events are simple although they do require knowing about accessors, keywords, functions, etc.
@BrunevaStudios
@BrunevaStudios 4 жыл бұрын
@@CodeMonkeyUnity So mostly learned programming from online tutorials, but I never got proper lessons, so I fail to understand some basic concepts. What I'm struggling to understand is how do I apply this in systems I am trying to create. I'll check out some other tutorials to see how you implement events! Thanks for the reply!
@arch454
@arch454 4 жыл бұрын
Excellent video been struggling with events, not any more
@kopilkaiser8991
@kopilkaiser8991 2 жыл бұрын
Best teacher in utube man. Nothing else to say.
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
Thanks for the kind words!
@chethansiqaandiostuff7365
@chethansiqaandiostuff7365 7 ай бұрын
I just Unity events to solve a horrible problem I had. Thank you so much Code Monkey for these wonderful tutorials. May God bless u in abundance
@Michael-px9il
@Michael-px9il 4 жыл бұрын
Thank you for these tuts. Im very new to C# scripting and am really enjoying the vids that you've been uploading on C# basics. Please continue them ;)
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Glad you like them!
@Runix1
@Runix1 2 жыл бұрын
Don't mind me, just feeding the algorythm as I'm here for the tenth time and can't upvote the video more.
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
Heh events are awesome but can definitely be tricky to understand, keep at it!
@personalgamedevyt9830
@personalgamedevyt9830 2 жыл бұрын
Events are simple and powerful! Thank you again for teaching the concept here and in your "Turn Based Strategy" course! It was way more than what I paid, and I learned so much while having fun!
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
I'm glad you're enjoying the course! Thanks!
@dougwarner59
@dougwarner59 3 жыл бұрын
Note: As I learned more about C# I had to update my post. I think this video is amazing; it demonstrates a great way to use events in unity. But...Even though the code is rock solid the explanation for the need of the event seems inadequate. Biased on your description you really don't need to use an event you could simply use a delegate. You said the key thing is the publisher does not know who the subscribers are...that can be done with just using a delegate instead of an event. (note: while the event is inside of the publisher class an event can be accessed just like an delegate, so the publisher doesn't see any difference between the two.) the reason you us a event over a delegate is the evert prevents subscribers from interfering with other subscribers by limiting the subscribers access to only the delegate's subset ( += -=) features. You can proves this yourself: remove the event keyword; the code will still work, but now the subscribers have the ability to change and invoke the delegate(which is a very-very bad thing.)
@russellkemmit73
@russellkemmit73 4 жыл бұрын
Wow, best Events explanation I have come by. I would suggest using console apps so that we can follow along 100%, but the instructions was so clear I had no issue following with a console app.
@13michal9
@13michal9 4 жыл бұрын
At 5:05 you said "awesome" which reminded me about Brackeys... oh no... I'm not crying... ;-;
@franziv4593
@franziv4593 4 жыл бұрын
Thanks for the work. Used to play around with unity and c# some years ago and have forgotten all. This is a good refresh.
@aaronnicholson8154
@aaronnicholson8154 4 жыл бұрын
Thanks for a thorough yet concise explaination. Perhaps the best explaination of events I’ve seen.
@yoctometric
@yoctometric 4 жыл бұрын
If only I had seen this video before i started making my game... Thank you! I have learned a lot from this
@TheAtticus82
@TheAtticus82 Жыл бұрын
Dude, this was exactly what I was looking for--great stuff!
@robosergTV
@robosergTV 4 жыл бұрын
Correct me If I am wrong but plain events like shown in the video are still a tightly coupled system since you use a particular event name in your code to subscribe and listen to events. In this case, you use "on SpacePressed", if you change that event in the publisher - all the listeners with that code won't work. Also for adding listeners, if you are getting a direct reference to the event publisher to subscribe that defeats the whole principle of decoupling, you might have as well not used events at all and just do a direct function call. In my opinion a truly decoupled event-driven system would be a pubsub pattern, where you publish messages under a specific topic and a payload and other listeners can subscribe to the topic (without knowing a particular event name, only the name of the topic)
@CodeMonkeyUnity
@CodeMonkeyUnity 3 жыл бұрын
The Publisher is decoupled from the Subscribers (doesn't care if anyone is listening) but the Subscribers are indeed coupled with the Publisher. That's intentional. For example if I have a Health System then I don't care if there's a visual for it but if I have a visual then it needs to have a reference to the original Health System. What you described is adding another layer of abstraction on top by making a dedicated Event Handler. Doing that does keep things even more separate but at the cost of extra complexity.
@chimz8057
@chimz8057 Жыл бұрын
As a designer, having programmed at the bare minimum level to get my stuff working for nearly 2 years, watching your videos makes I realize I know nothing about coding xD Thank you! These are very useful
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
Heh there's always more to learn! It's a lifelong journey
@DutchJDoe
@DutchJDoe Жыл бұрын
Concise but fully and simple explained, I like that, you really have talent !............THX !
@windwalkerrangerdm
@windwalkerrangerdm 2 жыл бұрын
Thank you codemonkey, couldn't remember how to relay some structured objects as eventarguments and remembered it through your video! Coming in very handy in the project I'm currently working on.
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
I'm glad the video helped you! Best of luck with your project!
@jonr7259
@jonr7259 3 жыл бұрын
Like others here I have been scanning the internet all day trying to get the hang of this, the other examples I found were way too complex and failed to just do the minimum to explain, as you did perfectly. It would have nice to include Unity events with parameters but I feel I can go back into the wild and find some other tutorials that will not be as good but you have given me the tools to beat them into submission.
@jannaukoko3390
@jannaukoko3390 2 ай бұрын
This is everything I was looking for! Thank you!
@kitthekat6844
@kitthekat6844 4 жыл бұрын
I recently learned about these, and now am using them a lot. Really cool tool to use!
@am385
@am385 4 жыл бұрын
One important distinction with the null conditional operator is that it sets a local variable to that first before checking null. This way it can maintain the thread safety it needs to not throw randomly. // this OnSpacePressed?.Invoke(this, EventArgs.Empty); // is actually this var onSpacePressed = OnSpacePressed; if(onSpacePressed != null) onSpacePressed.Invoke(this, EventArgs.Empty);
@spudyminoguesgames8036
@spudyminoguesgames8036 2 жыл бұрын
Fantastic stuff, I wish I had watched your tutorials ages ago, I just finished my first game see loads of places where the code could have been done much simpler and better. Just got your 50++ course will be going through that before starting the second one, keep up the great work.
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
Yup Events are definitely a game changer when you learn about them, best of luck in your learning journey, I hope you like the course!
@kopilkaiser8991
@kopilkaiser8991 2 жыл бұрын
Code monkey is the best. All the way till the end. ⭐️⭐️⭐️
@chaosmastermind
@chaosmastermind Жыл бұрын
I'm going to have to watch this at least 5 more times to get it, but this is definitely the video to watch. Events are super confusing.
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
Yeah they do take a while to fully understand but once you do you will have added an extremely powerful tool to your toolbox!
@vaderporpoise774
@vaderporpoise774 4 жыл бұрын
your tutorials are awesome, thank you for covering these topics, you barely skipped over any basics while keeping a good pace, I really appreciate it
@sagrgywejhxcvx
@sagrgywejhxcvx Жыл бұрын
best of all event tutorials, thanks
2 жыл бұрын
I need to create some events today, but I forgot how to do that. You are a life saver (again) :-)
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
Hehe that's great, I'm glad the video helped! Events are awesome!
@programmervideos8163
@programmervideos8163 4 жыл бұрын
Very clear and good explained video, thank you sir and all your supporters!
@shuashuashua1
@shuashuashua1 4 жыл бұрын
Sometime ago I was looking for diffrence between Event and UnityEvent, there is diffrence in CG allocation one Event allocate less garbage than one Unity Event, but 10 Unity Events allocate much less garbage than one Event. Delegate Events are much faster than Unity Event - 4 years ago someone tested it on reddit. This may have changed because the articles are from 2016. Sources: jacksondunstan.com/articles/3335 www.reddit.com/r/Unity3D/comments/35oekm/delegate_events_vs_unityevent_which_one_is/
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Interesting, I dont usually add and remove event subscribers lots of times so never had issues with garbage, good to know!
@SkinnerSpace
@SkinnerSpace Жыл бұрын
Nice lesson, I've been using events for a while but I just get stuck with Actions only and never even considered other ways of implementing this kind of observer pattern. Now I'm gonna try all of them and decide in which cases some of them are more convenient than others. Thanks!
@papaluisre
@papaluisre 4 жыл бұрын
Best video on Events I've seen so far!
@InamiLanzhu
@InamiLanzhu Жыл бұрын
thankyou, it's super clear especially after watching the delegates tutorial
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
I'm glad the video helped! Thanks!
@kopilkaiser8991
@kopilkaiser8991 Жыл бұрын
Great tutorial. I was able to learn all the concept pointed and taught on this video.
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
I'm glad the video helped! Thanks!
@TarzantheNinja
@TarzantheNinja 4 жыл бұрын
These tutorials have been immensely helpful to my team in school. Please do make a delegate video
@MohamedMagdy-ql3pl
@MohamedMagdy-ql3pl 4 жыл бұрын
A video about delegates would be absolutely appreciated.
@empressredbird
@empressredbird 2 жыл бұрын
I'm excited to incorporate this into my next project!
@kaseywahl
@kaseywahl 2 жыл бұрын
I'm not a game dev, but I use the Azure EventGrid when I build APIs in the cloud. This helps a lot!
@CodeMonkeyUnity
@CodeMonkeyUnity 2 жыл бұрын
Yup C# works mostly the same in game dev or software dev, it's a really awesome super versatile language!
@b.c.a683
@b.c.a683 Жыл бұрын
solid explanation and clear way, thank you !
@n0ut4j4
@n0ut4j4 3 жыл бұрын
Excellent video. First one to really explain this in an understandable and simple way. Thanks!
@recepcakir4866
@recepcakir4866 4 жыл бұрын
I didn't quite understand one thing; At the beginning of the video, it is mentioned that an event does not know or care if it has any subscribers, but at 4:25 it throws a null reference exception because we do not have any subscribers. Can anyone explain this, please?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
The event is an object, if it has no subscribers then it defaults to null. So you do need to do a null check.
@recepcakir4866
@recepcakir4866 4 жыл бұрын
@@CodeMonkeyUnity How does the event get rid of the null state? Does it get out of the null state after first pressing of space button?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
@@recepcakir4866 You only trigger the event if its not null if (OnMyEvent != null) { OnMyEvent(this, EventArgs.Empty); }
@MuhammadAsad-qp8ou
@MuhammadAsad-qp8ou 4 жыл бұрын
make a video on delegates and lambda expression. both makes code easier to read and write.. thats the main video we want. Glad u started making c# videos in unity. that means alot to us
@512Squared
@512Squared 2 жыл бұрын
It was good to see all these versions used together
@takeawayplease6229
@takeawayplease6229 9 ай бұрын
This video made me understand events! Thank you!
@CodeMonkeyUnity
@CodeMonkeyUnity 9 ай бұрын
I'm glad the video helped you! Thanks!
@wintercaesaria2492
@wintercaesaria2492 Жыл бұрын
Thank you so much for explaining this. After so long I've finally understood this.
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
I'm glad the video helped! Thanks!
@reddragon6317
@reddragon6317 4 жыл бұрын
At last. Finally i understand . thanks mate, saved me a lot of work. you have earned my subscription with this. good luck.
@sagiziv927
@sagiziv927 4 жыл бұрын
You forgot to mention that if we want to use a generic UnityEvent (That takes arguments) we need to create an empty class that inherits UnityEvent
@JackieCodes
@JackieCodes 3 жыл бұрын
10:09 you're subscribing to the event at start, getting the argument and saying how many times it was pressed and then you're unsubscribing, so why does it keep counting how many spaces pressed if you unsubbed after first event fired?
@ABCshake
@ABCshake Жыл бұрын
Great video. You know sometimes I imagine Code Monkey typing with his tung out like the avatar.
@gizel4376
@gizel4376 4 ай бұрын
so basicly it's the same as making a void publisher() { subscriber1(); subscriber2(); } void subscriber1() {do something;} which i did quite a few times, but it's more dynamic since you can remove or add the function from the publisher during runtime
@CodeMonkeyUnity
@CodeMonkeyUnity 4 ай бұрын
Yup exactly! With the big difference being the publisher does not know the listeners exist, it does not need to have a direct reference to them, it just invokes the event and the listeners run their listener function.
@ASMRcu
@ASMRcu 4 жыл бұрын
Wow thanks sir. You r making us CodeGorilla 😍
@Arkl1te
@Arkl1te Жыл бұрын
This also helps me with Godot, which also has C# support. Thank you!
@ryrilya2289
@ryrilya2289 4 жыл бұрын
Excellent tutorial! Thank you kindly.
@ardawanx
@ardawanx 4 жыл бұрын
awesome tutorial. way better than the official tutorials from unity haha. Tnx
@BingoGo2Space
@BingoGo2Space 8 ай бұрын
I love you, code monkey!!! You are my favourite teacher officially now❤❤❤❤
@CodeMonkeyUnity
@CodeMonkeyUnity 8 ай бұрын
I'm glad my videos have helped you!
@cradle_of_chaos
@cradle_of_chaos 4 жыл бұрын
This is excellent work. Keep it up.
@bathtubanarchy
@bathtubanarchy Жыл бұрын
I just finished Unity's Junior Programmer pathway and I *really* wish I'd watched this video about halfway through. My projects were always collapsing under their own weight towards the end, because something wouldn't work quite how I expected, which would mean I'd have to change one thing and then have to change everything that came before it to accommodate that change.
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
Heh yup events are excellent for helping exactly with that. In my free course I made an effort to constantly mention the importance of using events to decouple code kzbin.info/www/bejne/d56qhHh-bLaWesk
@lorenzocgt1021
@lorenzocgt1021 4 жыл бұрын
Thank you ! My code is so much cleaner after your video !
@GameDevCaptainBlack
@GameDevCaptainBlack Жыл бұрын
thanks buddy, today i used this eventhandler in my project
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
Nice! I hope it helped! I love events
@mirkoemir
@mirkoemir 4 жыл бұрын
Great tutorial and very clear!! thank you.
@Dr2quan
@Dr2quan 2 жыл бұрын
Thanks, clear and elegant.
@learnsmtheveryday01
@learnsmtheveryday01 2 жыл бұрын
Thanks it was super easy to follow and implement in my own game
@mibo747
@mibo747 4 жыл бұрын
Thank you ! Perfect explanation!!!!!
@MikeStock88
@MikeStock88 2 жыл бұрын
Great tutorial, thanks for sharing, clear and concise
@mrmendee
@mrmendee 3 жыл бұрын
Cool! You are Event creator to me , i am just subscriber hehe Clearly understand that Standard Visual Studio C# usage EventHandler. And more, understood that UnityEvent system. Thanks to share!
@sabrango
@sabrango 4 жыл бұрын
Thx for all! before I tot coding is just public or private variables and functions........but then I realize that those custom-like functions in C# is Modern language.!
@AliveNotDeadmund
@AliveNotDeadmund 4 жыл бұрын
Once again you are making a difficult topic accessible! Love your work, mate! Many thanks. :D
@sangeetajethuri801
@sangeetajethuri801 4 жыл бұрын
Is there a reason to use EventHandler delegate instead of Action ? Action has much simpler syntax and we don't even need to make a separate class to pass parameter. So why do you prefer using EventHandler ?
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
Just because that's the standard, that way all events work exactly the same way and if I need more data I just use EventArgs. It is more lines but I value having standardized code more than making it shorter, also I don't tend to use custom EventArgs too often. But yes using Action works functionally the same.
@sangeetajethuri801
@sangeetajethuri801 4 жыл бұрын
OK thank you for reply.
@brief9824
@brief9824 3 жыл бұрын
Thank you for the video. Really helpful. Question: What are pros and cons of Event System as a separate class with all the events vs events scattered around in scripts?
@ivanshiek
@ivanshiek 2 жыл бұрын
Use whichever you want and you'll soon come across the pros and cons of it. Hopefully before the end of your project.
@marcelgehtdichnixan5370
@marcelgehtdichnixan5370 Жыл бұрын
4:19 "Press Space" *sends spacebar to heaven* "There we go! We have an error" I love you
@bsdrago
@bsdrago 4 жыл бұрын
Yes, please, a video about delegates and relationship with events. Keep the good job. I will become a patreon very soon. =)
@cosmicevo1266
@cosmicevo1266 3 жыл бұрын
Thank you so much, I finally understood the concept a lot better now😊
@fabriciodorneles
@fabriciodorneles 4 жыл бұрын
Very Nice! Thanks Man! You're Awesome! It's so good to have your tutorials!!!
@tigransahakyan2840
@tigransahakyan2840 4 жыл бұрын
Great c# course started :) keep going!
@gambar
@gambar 4 жыл бұрын
Sorry for a noob question, but in the subscriber (in the Start()), why are you using the += operator instead of just = ? (5:40-ish mark)
@CodeMonkeyUnity
@CodeMonkeyUnity 4 жыл бұрын
If you do = then you erase all the subscribers currently on the event and replace it with just that one. With += you add another subscriber while not modifying the current list of subscribers. Also you cannot use = when accessing the event from other classes, you can only += or -=
@gambar
@gambar 4 жыл бұрын
@@CodeMonkeyUnity thank you so much for your response!
@krishnaasinghbisht
@krishnaasinghbisht Жыл бұрын
from where can i learn c# for game development from beginner to advanced that i can write my code on my own ( i have little bit of experience in java and c++) , can you suggest the resourses(books, youtube tutorials , etc)
@CodeMonkeyUnity
@CodeMonkeyUnity Жыл бұрын
I recommend my quick C# overview video to get a quick overview of the language unitycodemonkey.com/video.php?v=IFayQioG71A Then if you want a complete guide check out my free course which starts on the beginner level and ends in intermediate unitycodemonkey.com/kitchenchaoscourse.php
What are Delegates? (C# Basics, Lambda, Action, Func)
18:39
Code Monkey
Рет қаралды 303 М.
What are Interfaces? (C# Basics)
13:54
Code Monkey
Рет қаралды 214 М.
번쩍번쩍 거리는 입
0:32
승비니 Seungbini
Рет қаралды 182 МЛН
«Жат бауыр» телехикаясы І 30 - бөлім | Соңғы бөлім
52:59
Qazaqstan TV / Қазақстан Ұлттық Арнасы
Рет қаралды 340 М.
Жездуха 42-серия
29:26
Million Show
Рет қаралды 2,6 МЛН
How To Build An Event System in Unity
8:01
Game Dev Guide
Рет қаралды 417 М.
Why you should NOT make everything PUBLIC!
8:26
Code Monkey
Рет қаралды 122 М.
2 Years of C++ Programming
8:20
Zyger
Рет қаралды 186 М.
C# Events & Delegates
17:21
Tarodev
Рет қаралды 91 М.
The MOST WANTED Unity Feature is FINALLY here!
12:15
Code Monkey
Рет қаралды 52 М.
.NET and C# are in trouble. Here is what I'd do.
10:57
Ed Andersen
Рет қаралды 116 М.
Learn C# Beginner FREE Tutorial Course! [2024]
3:56:51
Code Monkey
Рет қаралды 171 М.
Events or UnityEvents?????????
15:43
Jason Weimann (GameDev)
Рет қаралды 105 М.
번쩍번쩍 거리는 입
0:32
승비니 Seungbini
Рет қаралды 182 МЛН