C# Events & Delegates

  Рет қаралды 92,725

Tarodev

Tarodev

Күн бұрын

Пікірлер: 241
@potatopassingby
@potatopassingby 2 жыл бұрын
"A delegate is just a variable which holds a method instead of data" omg this helped me understand it right away. It's SO SIMPLE but nobody explains it simply that this is all it is lol. Thanks!!
@Tarodev
@Tarodev 2 жыл бұрын
A statement so powerful I added it as text to the screen 😊
@vzx
@vzx 2 жыл бұрын
Back in the day, I kept hearing "function pointer" on C++ technical interview, delegates basically the C# version of that.
@diligencehumility6971
@diligencehumility6971 2 жыл бұрын
If you have someone explaining things to you in a straight and simple manner, actually, even complicated things becomes understandable. I had a similar realization, when I looked into delegates / Action / Func - but from another KZbinr, some years ago. This guy (Tarodev) is excellent - things like this makes me believe in humanity again. People helping each other online, for no other reason than being nice / polite to others.
@jesusmgw
@jesusmgw 2 жыл бұрын
Yeah exactly. I guess many experienced devs are afraid of using words like "variable" and "function" while teaching because they sound too basic.
@hassanshah2129
@hassanshah2129 Жыл бұрын
@@Tarodev seriously man 😊
@aarongeorge347
@aarongeorge347 2 жыл бұрын
I came here looking for a solution to fully decouple my game scripts, and walked away with the wisdom that it doesn’t need to be that way. Thank you, Matt!
@sasquatchbgames
@sasquatchbgames 2 жыл бұрын
You've made my life as a developer much easier, many of your tutorials have come in handy, thanks so much for all the hard work you put in!
@Tarodev
@Tarodev 2 жыл бұрын
Glad I could assist you on your journey ❤️
@derboss66
@derboss66 9 ай бұрын
Hey wtf, i actually watched a few of your videos xD
@TheKr0ckeR
@TheKr0ckeR 2 жыл бұрын
Using these with Scriptable Object is the best thing I've ever learned actually.
@Etienne_H
@Etienne_H 2 жыл бұрын
Can you name a use case? Would be helpful.
@kyleme9697
@kyleme9697 2 жыл бұрын
@@Etienne_H For the UI. You could have a bullet hit something, and either the bullet or the object it hit could register it in the game by calling a "Hit" event. Then you can have the UI listening for the Hit events, and updating a scriptable object that is recording Total Hits, etc. Then the UI would read from the scriptable object every second. (I don't know how this would perform with thousands of bullets flying around, its just an example.)
@Etienne_H
@Etienne_H 2 жыл бұрын
@@kyleme9697 Ok, thanks
@nerdin8or
@nerdin8or 2 жыл бұрын
Gotta say, this all makes way more sense after working for a few years as a front end dev with React. JavaScript, especially React, does this all the time.
@cobrauf
@cobrauf 2 жыл бұрын
This is hands down the BEST video on events/delegates in Unity.
@windup247
@windup247 2 жыл бұрын
So many people sound like they're just reading from the docs when teaching something. I'm always amazed at how you DON'T do this, but really deliver the material in an understandable way. Brilliant video.
@andreasmetz2438
@andreasmetz2438 2 жыл бұрын
This was definitely the most compact and best explanation of events that I've heard so far.
@muddrosal8065
@muddrosal8065 2 жыл бұрын
I've been trying to understand exactly what a delegate is for far longer than I would like to admit. This clear and concise example at the start of the video just made it straight up obvious. Thank you!!
@xxxgames7458
@xxxgames7458 2 жыл бұрын
Why am I understand this now after so much studying?? Damn hell . Bless man
11 ай бұрын
Loved that this is one of the first videos about events that the person mentions the downside of events/decoupling, which is lack of clarity, and harder debugging, so it's something to definitely use with caution, especially the "static" version of it, since you now can subscribe from literally any script without even holding a reference to a specific instance. Really nice video!
@liquidsword926
@liquidsword926 2 ай бұрын
your videos are so straight to point that I know if it's 17mins, it should be
@ScrewY0UguyS
@ScrewY0UguyS 2 жыл бұрын
I thought I knew the topic but you somehow always add to my knowledge. Thanks to you I found out what "event" keyword does and how "Func" differs from "Action". Your explaining is so wide and simple at the same time. Thanks!
@josephramos6939
@josephramos6939 2 жыл бұрын
I love that you used real world practical gaming examples. Sometimes I learn about these new programming concepts but its not clicking why I would use them.
@TheSeanC
@TheSeanC 2 жыл бұрын
I feel like this is a video I will keep coming back to. Lots of little nuggets in there about delegates and events. Thank you!
@TylerLarson
@TylerLarson 2 жыл бұрын
Ok, Tarodev, gotta say, this was a really good video. I started programming in C# at my first official job in 2003 (ya, v1.0, when most people thought .NET was a super sketchy idea), and I learned all these language features that long ago. AND YET, I still learned something by watching your video. And I was engaged the whole time. Srsly, excellent job.
@mrstruijk
@mrstruijk 2 жыл бұрын
Thank you Taro! You’re the first one I met in 4 years of dev who explained delegates, func, and actions clearly and succinctly
@Tarodev
@Tarodev 2 жыл бұрын
That's high praise 😊 tha ms maarten
@baoinh2968
@baoinh2968 Жыл бұрын
thankyou so much! You are one of the few people on KZbin teaching Unity that I can understand
@simonwahlstrom1296
@simonwahlstrom1296 2 жыл бұрын
This should have a million views. Your channel is amazing. Thank you so much for everything you are doing and for the quality of your content!
@Tarodev
@Tarodev 2 жыл бұрын
Thank you for the kind words Simon 🙏
@GameDevNerd
@GameDevNerd 2 жыл бұрын
A delegate is literally a fancy, managed wrapper for a function pointer. You can even obtain a function pointer from native code and marshal it into a C# delegate, then pass that delegate around and call it just like any other delegate. This can also work in reverse. Under the hood, a delegate _is_ a function pointer, it just uses a different declarative syntax and hides the actual address and other complexities from you so it can be used more intuitively. I manually declare delegates sometimes, but many of the most common signatures you'd want to use already have a predefined version like a delegate void with no parameters or several parameters can be declared with Action and Action and when you want to return stuff there's Func and Func (there's variants with numerous parameters like T1, T2, T3, etc). That covers a _lot_ of delegate usage, and it's hard to think of some it won't cover. So why ever declare your own? Well, for intuitive and expressive naming, of course! It can clearly express your intent as a programmer and also make things a bit more type safe. You may not want to use Action for an event representing two totally different things so no one can confuse the two and create hidden bugs that can be hard to find. If it just uses an Action or Func, you can easily have another programmer mix stuff up and have criss-crossing events creating undesirable or fatal behaviors. But if you have two types of delegate clearly named things like _MenuActionDelegate_ and _KeyInputDelegate_ it gets much harder to confuse those things or use the wrong thing! That's a pretty contrived example, but in a real project you'll see how that makes sense if you think about it ... So, sometimes, it's actually kind of _smart_ to manually define a custom delegate, even if that signature is already defined by built-in ones like Action or Func. Keep in mind, there's _nothing_ special about Action or Func, they're just common delegate declarations exactly like the ones we declare ourselves. Many people don't know this and think those are some kind of special classes with their own fancy code but they're not. This is literally the definition of Action, as follows: public delegate void Action(T obj); That's it! That's the entire definition/implementation of Action, just a common delegate with one generic parameter. Nothing special about it other than what the .NET Framework does beneath the hood with _all_ delegates we declare. Microsoft just included these built-in delegate definitions so we'd all have predefined ones that cover almost all the use cases, so we wouldn't have to waste time or add clutter to code if it didn't make any sense to. If I want to quickly use a delegate in one place in my app and be done with it, I'd hate to have to stop and decide where I should go define a delegate signature and then come back to my method I was working on and use it ... much easier to just use a Func or something as a temporary use delegate. But anytime I'm creating something like a custom event system that's consumed from other classes, I do take the time to define my own custom delegates for the sake of clarity and expressiveness ...
@GameDevNerd
@GameDevNerd 2 жыл бұрын
P.S. - As always, enjoyed the video and enjoy throwing in my two cents on these topics. It's refreshing to see someone teaching important C# fundamentals and good practices in the Unity world, as there's so much awfulness out there, haha. I share these videos with junior devs on our team that are curious about the topics and want additional information and they enjoy these too! 🙂
@Tarodev
@Tarodev 2 жыл бұрын
Amazing write up Aaron!
@notrhythm
@notrhythm Жыл бұрын
im a bit confused. "So why ever declare your own? for intuitive and expressive naming" couldn't you just use the predefined types but name it something that wouldn't cause confusion? eg. public event action MenuActionEvent; i dont see the need to declare your own delegates if the predefined ones fit your need
@tomeidk
@tomeidk 3 ай бұрын
i don't know how you do it but you make these concepts so easy to understand, thank you so much
@alfbs
@alfbs 3 ай бұрын
Probably the best video I found on this topic. Thank you!!
@seanloughran6714
@seanloughran6714 2 жыл бұрын
Your videos are better than Google. Quick, straight to the point with immediate examples. Thanks again!
@Tarodev
@Tarodev 2 жыл бұрын
That's some heavy praise
@joshuasanjuan3352
@joshuasanjuan3352 2 жыл бұрын
Of all the videos that discussed Events and delegates, yours is the most clear and concise. Good Job!
@eruchii7200
@eruchii7200 2 жыл бұрын
Man, the way you explain these stuff makes it very easy to understand. Thanks and great job 👍
@GoldenWind
@GoldenWind Жыл бұрын
Hi thank you for such a clear and whide explanation of the topic! good luck with your future content!
@leonidus101
@leonidus101 2 жыл бұрын
There are 2 reasons why I use more rarely (static) events: the subscribing/unsubscribing part and the "voyeur"-ability this functionality gives - everyone can subscribe, also he can subscribe redundantly, but I don't want that! I want to limit access and know exactly who gets triggered and who listens - you clearly state it in the video => REDUCED CLARITY! (bravo for giving Pros and Cons on the concept!!!)
@nomorecookiesuser2223
@nomorecookiesuser2223 11 ай бұрын
You've gotta love it when someone Really knows the subject matter, and how to relay it. That was an excellent explanation, thank you. You are a step above the other 'monkeys' :D
@aliengarden
@aliengarden 9 ай бұрын
This video (and channel) is an absolute gold mine. I really wish this was explained like this to me earlier, it's so clear now. Thanks for taking the time to put this together, I will recommend this video to any confused beginners I might encounter along my way.
@Tarodev
@Tarodev 9 ай бұрын
You're more than welcome :)
@konstantin9484
@konstantin9484 2 жыл бұрын
Was just researching how Events work to implement a scoreManager using events. This was really helpful, thank you!
@This-Was-Sparta
@This-Was-Sparta 2 жыл бұрын
Great tutorial as always, Taro. Thanks! Been using events for a while now, but it's good to have a clearer understanding of what makes them tick.
@svendpai
@svendpai 2 жыл бұрын
I've watched multiple videos on events, best one yet
@JW-uu9je
@JW-uu9je 2 жыл бұрын
I wasnt ready for this video when I first started watching but I have recently stated calling Unity Events so now I am able to understand this much better. Honestly your channel is amazing! Your personality is hilarious...love all the zingers!
@kopilkaiser8991
@kopilkaiser8991 2 жыл бұрын
Amazing. Easy and simple resource to learn and understand. As wel, you are fun to watch as you make it interesting with the great humour of yours.
@KeyboardKrieger
@KeyboardKrieger 2 жыл бұрын
All the video after you said you never use delegates I thought "what's with passing em down?" And in the end you even got this, nice work. I use em for these damn coroutines. In my game I want to know when the animation is finished and start something new. There delegates have been the best solution.
@alfonzo6320
@alfonzo6320 2 жыл бұрын
2:06 i was waiting for it and i'm very satisfied!💯
@manikghosh3141
@manikghosh3141 3 ай бұрын
This is 3rd video of yours i watched and made me subscribe. I am watching your whole playlist. Your explanation for me is somewhat different than other ones❤
@Tarodev
@Tarodev 3 ай бұрын
@@manikghosh3141 glad you are enjoying 😊
@anna_silver_moon
@anna_silver_moon 2 жыл бұрын
The addition at the end of the video from the next day is just super useful!👍
@thulko
@thulko 2 жыл бұрын
Great informative video! I was just reviewing events & delegates and this video taught me a few new things.
@LeviAckerman-xt7dx
@LeviAckerman-xt7dx 2 жыл бұрын
Beautifully done tutorial very beginner friendly
@Drrobverjones
@Drrobverjones 2 жыл бұрын
I've used delegates in my game mixed with interfaces to change the functionality depending on interactions. It's been super useful to allow my function to change and be called without me having to worry about what it is actually calling.
@KVBA
@KVBA 2 жыл бұрын
I already knew plenty of things about C#, but i could never wrap my head around how delegates work. Your video made it clear to me. Also, static events seem really useful for my stuff, and i cant really tell why i havent learned them before. Thank you! Best wishes!
@pirateskeleton7828
@pirateskeleton7828 2 жыл бұрын
I started using delegates in my game to implement the behavior system, since I can store all the behavior conditions and calculations within struct that I can put into a list and reorder as needed. Something else you can do is store class extensions functions as delegates, ex: function = this.extensionFunction. I do this to keep my scripts organized by defining the behavior functions themselves as extensions to my behavior class.
@bunggo9914
@bunggo9914 2 жыл бұрын
your explanation is better than most online courses, keep up your content!
@SuperTungbi
@SuperTungbi 2 жыл бұрын
love this content, please do a series about SOLID in unity with details, thank you so much for your work
@reggieisnotadog4841
@reggieisnotadog4841 Жыл бұрын
Well damn I wish I'd seen this years ago. I know how to use delegates but did not know that simplified way of writing them as Actions and static actions. Thanks!
@romansalnikov5079
@romansalnikov5079 2 жыл бұрын
Special thanks for the beautiful picture, beautiful buttons, beautiful sprites, in total - beatifull visual work in your videos which in no way relate to the topics of your videos, but it's very pleasing to the eye Probably this video not for beginners and your explanation not the best but doesnt matter, your videos so good It's like comparing buggy win 10 and mac os with amazing controls
@ShinichiKudoQatnip
@ShinichiKudoQatnip 2 жыл бұрын
Just what I needed from the cute dev 😍
@nextdawnstudios1342
@nextdawnstudios1342 2 жыл бұрын
I love the detail into C# in your videos. They have helped me strengthen my skills as a developer. I don't use Unity but I do use C# with Godot and your videos have helped me immensely. Keep up the great work and thank you for what you do!
@deaderontheinside6871
@deaderontheinside6871 2 жыл бұрын
Wow. The opening line on delegates taught me more than four years of studying game development.
@manuelgraca3118
@manuelgraca3118 2 жыл бұрын
Amazing video as always. Keep up the good work!
@maxfun6797
@maxfun6797 2 жыл бұрын
Nice video, kinda heavy, lots to absorb, but this has given me a good idea of what delegates, actions, event actions are. Thanks
@piotrone
@piotrone 2 жыл бұрын
Best explanation of delegates ever! So simple and easy to remember
@anna_silver_moon
@anna_silver_moon 2 жыл бұрын
I'm developing a small 3D game and your channel helps me a lot!
@sansavatar5929
@sansavatar5929 Жыл бұрын
You're the guy with the clearest explanation out there, thanks man
@subhajitadhikary816
@subhajitadhikary816 2 жыл бұрын
Really Helpful video, as usual, I recently found the 2048 and grid game video. Ngl those types of videos are really great for learning. I found it very helpful. Learned a lot, Thank you!!. Hope you make long videos like those covering a variety of topics.
@boooooooop
@boooooooop 2 жыл бұрын
Genuinely such a great and informative video, thankyou
@AlexBlackfrost
@AlexBlackfrost 2 жыл бұрын
That was a great video, Taro. Keep them coming!
@EminoMeneko
@EminoMeneko 2 жыл бұрын
Nicely explained. The essentials are here.
@robertquayle6945
@robertquayle6945 2 жыл бұрын
I'm not a religious man but, God bless you for this video. Thank you.
@Tarodev
@Tarodev 2 жыл бұрын
Thank you for the blessing. I can feel the warmth of it now (probably the sweltering Australian heat though)
@leadtoexemplify
@leadtoexemplify Жыл бұрын
It’s impressive to see how fast your brain works 👍
@kopilkaiser8991
@kopilkaiser8991 Жыл бұрын
Impressive tutorial. Thank you for taking the effort to teach us these topics 😊
@Tarodev
@Tarodev Жыл бұрын
I'm glad you enjoyed :)
@HelPfeffer
@HelPfeffer 2 жыл бұрын
Your videos are great, and very useful. Thank you
@tomkc516
@tomkc516 2 жыл бұрын
Man grooming on point!
@Tarodev
@Tarodev 2 жыл бұрын
Fresh cut
@khubayan8350
@khubayan8350 9 ай бұрын
I feel enlightened. Thank you.
@khubayan8350
@khubayan8350 9 ай бұрын
I'm literally tearing up right now
@soverain
@soverain 2 жыл бұрын
Nice summary. One note though: multicast is not about having the event keyword or not. It’s about registering multiple callbacks (methods) in the same delegate. In old versions of C#, there was two types of delegates, one for single cast delegate and one for multicast. They simplified the thing by only keeping the multicast one.
@Tharky
@Tharky 2 жыл бұрын
Awesome tut baby
@fmproductions913
@fmproductions913 2 жыл бұрын
That was very well explained!
@Tarodev
@Tarodev 2 жыл бұрын
Thank you FM my boy
@mathiasbauer3169
@mathiasbauer3169 2 жыл бұрын
Very useful information, thank you.
@WagnerGFX
@WagnerGFX 2 жыл бұрын
One thing I like about Actions is that you don't need a definition like Delegates, just the signature. A good tip is that if you are going to create some kind of custom "EventArgs" to send a group of data, prefer to use struct unless a class is necessary, that will generate less garbage. (that is the struct's function anyway 😁)
@hellhunter9478
@hellhunter9478 2 жыл бұрын
Nice video and nice information regarding's this topics. I will have to work with them in order to understand them better but now at least I have a general understanding of them so thank you for this video :)
@vivienlynn2585
@vivienlynn2585 2 жыл бұрын
@12:30 About unsubscribing; Normally I subscribe and unsubscribe exactly like you suggest here (@13:12). But in rare occasions, I found myself having to subscribe to events from multiple locations in my codes. This easily lead to accidental subscriptions to the same event multiple times, which results in it being fired multiple times with each call. In situations like this, it is possible to unsubscribe first, and then subscribe in the next line. If you are not already subscribed, nothing happens. If you are, you make sure to only add one listener.
@curtisodorizzi7779
@curtisodorizzi7779 2 жыл бұрын
I see some JB Rider shortcuts being used. I'd be interested in a video detailing some of the JB Rider tips as it relates to Unity development.. Maybe you can get them to sponsor the video or something :)
@seancarey4108
@seancarey4108 2 жыл бұрын
Overflow Archives has an excellent tutorial on how to create an EventManager on their channel.
@adventuretuna
@adventuretuna 2 жыл бұрын
In our workplace, we avoid using UnityEvent. This is because in the past we would spend hours debugging why Foo() is being triggered randomly only to see that Foo() is in a random UnityEvent in a random animation or prefab. The problem is that if a function is invoked by a UnityEvent, the stack trace will not say which object is invoking that function. The IDE will also mark the function as "not used" so it shows as greyed out and somewhere down the road, a new programmer works on the project and deletes the function tied to a UnityEvent causing all sorts of bugs. It's less designer-friendly but having functions be explicitly triggered through code only helps reduce bugs in general. This has somewhat been alleviated though ever since we all switched to Rider because Rider knows if a function is used in a UnityEvent.
@Tarodev
@Tarodev 2 жыл бұрын
This is a major problem for the entire scriptable object architecture workflow. It's toop hard to keep track of what's triggering what. I stick with standard functions, too.
@hefferwolff3578
@hefferwolff3578 2 жыл бұрын
Extremely helpful, thank you!
@RussiJislakki
@RussiJislakki 2 жыл бұрын
I try to keep the visualization / UI totally decoupled from game logic and Events (or UnityEvent more specifically) provide a good one-way communication between them. Though sometimes I run into a problem when subscribing and invoking happen in the same frame (new instantiated class subscribes to an event which invokes during the same frame - thus not triggering whatever function I wanted). Thanks for the video anyway! I've always found delegates to be hard to understand.
@jacobs.7925
@jacobs.7925 2 жыл бұрын
Outstanding video!! Quick question, how is the extension/add-on called at 5:23 ? The one that gives you choices to autocomplete/etc. Is there an alternative inside visualstudio? Thanks a ton!
@gorkemasrinkoksal6110
@gorkemasrinkoksal6110 2 жыл бұрын
You deserve everything
@Atezian
@Atezian 2 жыл бұрын
As soon as you added static to the Action ... Why not just call the functions directly? Using the Action made it more complicated and confusing.
@yummybunny7351
@yummybunny7351 2 жыл бұрын
1:44 that montage just kill me.
@marcioardanuy3089
@marcioardanuy3089 11 ай бұрын
Awesome explanation!
@leonidus101
@leonidus101 2 жыл бұрын
Dude, you create insanely useful, extremely well explained videos! I like your short on-spot examples to demonstrate everything. Keep up the good work! I hope you make a cooperative video with Jason Weimann and Codemonkey, so your channel gains more popularity. In my opinion you beat both of them: Jason sometimes drifts away from the topic and Codemonkey's tutorials gotta always get paused to check what he speedtyped and moved off screen immediately after that.
@Tarodev
@Tarodev 2 жыл бұрын
Thank you for the kind words 🙏 Hmm... I might watch 300 tonight
@leonidus101
@leonidus101 2 жыл бұрын
@@Tarodev :D just don't watch the sequel. I am being honest with you, watching constantly tutorials for a decade (since Brackeys entered and basically (re)defined the gamedev youtube tutorial scene) in case there is something new in Unity that I missed. You are really good at explaining. Fact.
@wendten2
@wendten2 2 жыл бұрын
I have a use case for the Func. I have a decoupled system for an RPG style character-trait system. (Charming, Strong, Brawler ect.) Every NPC in my game have a data script with an enum list of all the traits they have. However some trait a contraditary like Charming and Awkward. So I made a static func with a return type of bool that took the TraitEnum as an input along with a list of traits. Now I have another script stores all the data about the trait, their bonuses and which other traits they contradict This other script have a function of type bool CanAddTrait(Trait currentTrait, List OtherTraits) There is probably a better way to do this, but it solves my problem, separates the two classes, and is easy to do testing with
@Rubidev
@Rubidev 2 жыл бұрын
This "Taro" is actually better than Tsubasa :)🔥🔥🔥🔥🔥🔥🔥
@Altair8113
@Altair8113 2 жыл бұрын
Great video man! Maybe you could make another video with UniRx and reactive programming as a sequel to this one. Cheers!
@nemcy3668
@nemcy3668 2 жыл бұрын
This is fantastic! You explain the subject so clearly, it helped me out so much. Do you have any plans to cover Observables in the future? I'm trying to learn it at the moment but there doesn't seem to be many tutorials out there that cover the subject in detail.
@leomac3464
@leomac3464 7 ай бұрын
Thanks. I took a lot out of that.
@MarceloSantos-rk5ee
@MarceloSantos-rk5ee 2 жыл бұрын
Very good video, thanks!
@vinhnghiang1273
@vinhnghiang1273 Жыл бұрын
For those who dont understand. Dont worry. Just watch it a 47th time like me. You will get it
@DanPos
@DanPos 2 жыл бұрын
Jason and Taro sitting in a Guild Hall...
@JimPlaysGames
@JimPlaysGames 2 жыл бұрын
Dude. This is so fucking useful.
@Mecheka
@Mecheka 2 жыл бұрын
On the Event part. I guess you did not mention it in order to keep it simple, but events can also have "add" and "remove" which function like a getter/setter on a property. You can check for not having duplicate listeners or methods with this.
@Tarodev
@Tarodev 2 жыл бұрын
I didn't mention it because it completely slipped my mind, lol! Thanks for writing it here
@Aryazaky
@Aryazaky 2 жыл бұрын
How do I write that? Static event Action OnSomething { add; remove; }?
@Mecheka
@Mecheka 2 жыл бұрын
@@Aryazaky yes, like a get/set, you can add {} to the add and remove and do things inside. Note that you need an underlying private delegate. Just like a property. You can then use the GetInvocationsList().Contains to check if the listener being assigned is already assigned. Or any other thing you want.
@MalikenGD
@MalikenGD 2 жыл бұрын
Wanted to ask... You say around 7:00 onward that you can use events to decouple, but from what I understand, subscribing to events is tight coupling because you have to have a reference to the classes anyway? Can you help me understand why this is not considered coupling but, say, static classes are?
@Tarodev
@Tarodev 2 жыл бұрын
The way I use an orchestrator class (the main method in this case) to hook up the events is what makes it decoupled. Those three classes have no idea of one another. You can use scriptable objects to take this a step further, which I'll be covering shortly
@osamarashid7493
@osamarashid7493 2 жыл бұрын
tarodev please make series on oop with example like these
@Ak-zm3ce
@Ak-zm3ce 8 ай бұрын
great teaching skills
@ViniciusNegrao_
@ViniciusNegrao_ 2 жыл бұрын
I've heard of delegates but never even conceptualized the idea in my head while I was using it left and right on javascript. I even learned actions and func before delegates and events and it seems so much easier this way. I have to admit I found delegates way too convoluted in c#
@gabaguiarp
@gabaguiarp 2 жыл бұрын
Great explanation! I became a huge fan of events since I discovered them, but at a certain point I also became too obsessed. As you say in the end, it's good to decouple things when needed but sometimes it might just make your game architecture overly complicated if you decouple too much. One question I have is: for objects that are constantly being enabled/disabled I usually subscribe to events on OnEnable and unsubscribe on OnDisable. But what about objects that remain enabled throughout the lifetime of a scene and only get disabled/destroyed when a new one is loaded? I usually subscribe on Awake, in those cases... but should I bother to unsubscribe on OnDestroy anyway?
@Director414
@Director414 Жыл бұрын
I'm constantly disabling UI-elements and I have trouble getting events to work properly. I was wondering if instead of disabling/enabling, it was better to make the UI-elements invisible? But you claim here it works if you assign the subscription in the Awake? Do you mean C# or Unity-events, or both? P.S. If you know any good videos for learning proper UI-programming in Unity please share, I find it somewhat cumbersome or hard to wrap my head around.
@ViniciusNegrao_
@ViniciusNegrao_ 2 жыл бұрын
3:00 NICE!
@Tarodev
@Tarodev 2 жыл бұрын
;)
@Mecheka
@Mecheka 2 жыл бұрын
My final comment before going back to work. I learnt not long ago that local functions are much more efficient than anonymous functions (local function: you can declare a function inside a function) I guess round 2 on the amazing performance vid could be great?
@Tarodev
@Tarodev 2 жыл бұрын
I'm a strong believer in local functions and use them a lot, but had no idea how the performance benefit. I'll have to look into that. I think I'll be doing round two benchmarking very soon.
@Mecheka
@Mecheka 2 жыл бұрын
@@Tarodev Yeah! I just heard of it, I might be very wrong on this. I'll await your vid :)
@RealisiticEdgeMod
@RealisiticEdgeMod 2 жыл бұрын
I dont use events. Theyre not flexible enough. I use Actions.
Unity Code Optimization - Do you know them all?
15:49
Tarodev
Рет қаралды 202 М.
10 Things You NEED to Be Doing in Unity
11:40
Tarodev
Рет қаралды 138 М.
Cheerleader Transformation That Left Everyone Speechless! #shorts
00:27
Fabiosa Best Lifehacks
Рет қаралды 16 МЛН
Правильный подход к детям
00:18
Beatrise
Рет қаралды 11 МЛН
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
What are Delegates? (C# Basics, Lambda, Action, Func)
18:39
Code Monkey
Рет қаралды 305 М.
Are events in C# even relevant anymore?
16:19
Nick Chapsas
Рет қаралды 172 М.
Events & Delegates in Unity
13:20
Game Dev Beginner
Рет қаралды 66 М.
Events or UnityEvents?????????
15:43
Jason Weimann (GameDev)
Рет қаралды 105 М.
Delegates in C# - A practical demonstration, including Action and Func
1:09:11
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 908 М.
C# Generics - The complete guide
18:43
Tarodev
Рет қаралды 42 М.
What are Events? (C# Basics)
15:05
Code Monkey
Рет қаралды 408 М.
Cheerleader Transformation That Left Everyone Speechless! #shorts
00:27
Fabiosa Best Lifehacks
Рет қаралды 16 МЛН