C# Events in Unity

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 พ.ย. 2024

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

  • @InfallibleCode
    @InfallibleCode  4 ปีที่แล้ว +7

    📦 Download the code at www.patreon.com/posts/35573982

  • @KarasawaL30
    @KarasawaL30 4 ปีที่แล้ว +116

    I know people find the format silly, but honestly I think this is the best way I've been able to learn these concepts so far. Better than some overly happy dude telling me how easy it is while royalty free music blasts my ears and he codes right past me at 2x speed. Then tells me how easy it was.
    But I'm not bitter or anything. Anyway awesome tutorial, thank you very much!

  • @QuietSnake-xs5vx
    @QuietSnake-xs5vx 4 ปีที่แล้ว +147

    i wish i could Skype myself for answers

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

      I have a boardgame about time travel, the main mecanic is to get ressource from your futur self, but then in the futur when the you from the past ask ressource, you have to give him otherwise you'll create paradox...
      i feel like this situation is similar, if i can call my futur self for coding advice that mean in the futur i'll be forced to answer skype call to give coding advice to myself

  • @EduardoYukio
    @EduardoYukio 4 ปีที่แล้ว +24

    This is the most didactic type of tutorial I've ever seen. It's short, walks you step by step, shows you every click and alt-tab, teaches you the definition of the concept and its usability, just perfect.

  • @brice.v
    @brice.v 4 ปีที่แล้ว +118

    the content quality outweighs the cringe of the acting, and that says something :) gj

    • @InfallibleCode
      @InfallibleCode  4 ปีที่แล้ว +32

      It’s a delicate balance lmao

    • @IconoclastX
      @IconoclastX 4 ปีที่แล้ว

      Lol

    • @rikdenbreejen5230
      @rikdenbreejen5230 4 ปีที่แล้ว +8

      ​@@InfallibleCode, I think you mean that it's a DELIGATE balance!
      Sorry terrible joke!

    • @monkeyrobotsinc.9875
      @monkeyrobotsinc.9875 3 ปีที่แล้ว

      @@InfallibleCode the ultra high humor factor keeps us going.

  • @ewwitsantonio
    @ewwitsantonio 4 ปีที่แล้ว +27

    I am definitely purple-shirt-charles in this story! Haha. This format is pretty funny but actually really helpful. Great work!

    • @InfallibleCode
      @InfallibleCode  4 ปีที่แล้ว +5

      LOL Purple shirt Charles’ name is Barles 😜

    • @prudhvi9256
      @prudhvi9256 4 ปีที่แล้ว

      😂

    • @prudhvi9256
      @prudhvi9256 4 ปีที่แล้ว

      @@InfallibleCode ​ Hey thank you guys for making these videos

  • @eierschaedl
    @eierschaedl 11 หลายเดือนก่อน

    Love that minimum effort of putting a cap on to represent another person XD
    I don´t know why it works, but it works.

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

    Now i see what seems to always make me quit a project.. tight coupling. entering the loop of fixing this and breaking that.
    I guess there isn’t an escape from watching an events tutorial.
    Liked.

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

    I love the "Cool" and "thanks" interaction over the keypad. Like 'yes we will be learning about Events here but also- how to give and receive a respectful compliment to a friend/coworker'.

  • @HadiExtreme
    @HadiExtreme 4 ปีที่แล้ว +4

    I just found your channel and this is the second video of yours I've watched. I really like this format! Subbed

  • @StefanLopuszanski
    @StefanLopuszanski 4 ปีที่แล้ว +6

    Huh, didn't know about the null conditional operator. That's neat.

  • @jikiller8530
    @jikiller8530 4 ปีที่แล้ว +6

    Can't thank you enough for making these videos, this "tutorial" and the interfaces one have really helped me. Subbed!

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

    These are so goofy, they make me smile throughout. Nonetheless a very effective way of communicating new concepts.

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

    "whatever floats your boat man" my favorite phrase for day or two

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

    I just realised that the whole 'bunch of doors and keys would slow down the code with useless checks' is the reason why Skyrim used to become slow. I remember being told to throw away my keys and suddenly the game's loading times were super quick haha.

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

    This video is perfect. Thank you for making it, I've been wondering about these for ages!

  • @jakem4638
    @jakem4638 4 ปีที่แล้ว +5

    Underrated channel, please keep up the good work!!

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

    I love the way you present information in a fun and easy way to remember. Keep up the good vids bro.

  • @Gabriel-ml7ev
    @Gabriel-ml7ev ปีที่แล้ว

    This format is hilarious it feels like an English lesson

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

    Awesome thanks man, this video is exactly the example I needed to get my head around which events system to use.

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

    Still, my number one channel to recommend to Unity beginners and intermediate. Gj man :)

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

    Man, this is a new level, you'll soon overcome brackeys in creativity :)

    • @onon128
      @onon128 4 ปีที่แล้ว

      Mrg Screen he is way more creative than brackeys

  • @illsaveus
    @illsaveus 3 ปีที่แล้ว

    This friend of yours is the nicest dood on the whole planet

  • @agredek
    @agredek 4 ปีที่แล้ว +3

    Nice video. Definitely will help some less experienced developers. Only one question comes to mind: in an example as simple as this, do we really need to create a delegate? Why not just use Action class?

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

    Can't wait for Charles and Charles for their Romance arc. 2:39

  • @scrawnyrabbit
    @scrawnyrabbit 4 ปีที่แล้ว

    So much pedagogy. Well done Charles !

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

    Sir you have a very good method of teaching! keep up the good work and thank you :)

  • @clement630
    @clement630 4 ปีที่แล้ว +23

    Day 40 of lockdown: talking to myself on skype

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

    3rd perfect video.Jobs,Interface and now Events.keep going with this type of videos please..people will be very glad..I am sure

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

    This video is ridiculously hand-holdy.
    ...
    and it's exactly what I needed ::sob:: THANK YOU SO MUCH

  • @keelanbowker-obrien2222
    @keelanbowker-obrien2222 4 ปีที่แล้ว +1

    Yeah acting aside this was actually an extremely helpful way to hep me understand the events system. The only thing I'd add is maybe some additional visuals when you're talking about the KeypadDoor.cs when you mention the matching signatures. I'm still a noob and because I don't understand the terminology, I didn't comprehend what was being conveyed there.

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

      Thank you for your feedback. I’m gonna make a follow up video that dives into a more advanced explanation so this is a great suggestion 👍

    • @keelanbowker-obrien2222
      @keelanbowker-obrien2222 4 ปีที่แล้ว +1

      @@InfallibleCode Wow! Thanks for responding and in general putting out just really great an informative stuff. This channel is just enormously helpful :)

  • @ruslanrakhimov1556
    @ruslanrakhimov1556 4 ปีที่แล้ว +5

    Charles is the type of dude to ask himself for help.

  • @austinheydari1813
    @austinheydari1813 4 ปีที่แล้ว

    i think it's better to pass the code (as int or string) as an argument for the unlockHandler.
    that way the logic to see if the code matches is in the door and not in the keypad. also if others subscribe to the keypad, you won't have to touch the door code anymore.
    Using interface for this is also recommended, you will be able to reuse your code more easily.

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

    y'all gonna be bigger than Brackeys. love the content!

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

    I was looking for this. Thanks!

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

    bro i love your channel....

  • @kbkmn
    @kbkmn 4 ปีที่แล้ว

    practical examples are great! do a factory method one. i can't grasp why do i need to use factory if i can just instantiate

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

    Love your videos Charles! Where have you been dude? Hope all is well.

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

      Just taking a little mental health break. But I’ll be back soon! Gonna get back to regular uploads in a few weeks 😄

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

      @@InfallibleCode Good to hear dude! Take all the time you need. We're just glad you're not dead : )

    • @InfallibleCode
      @InfallibleCode  3 ปีที่แล้ว

      @@Dbl_Plus_Good I really appreciate that! I'm still alive and kicking, and planning to resume regular uploads in a few weeks :D

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

    Thanks ma dude.

  • @simon.in.motion
    @simon.in.motion 4 ปีที่แล้ว +1

    Hello Charles, I wonder, why using C# events instead of UnityEvents for this example ? I find it way more modular to set a OnCodeSuccess UnityEvent and set the reference to the handler in the editor. That way you can also trigger AudioSources or other stuff without writing any more code, just adding it in the inspector. Any thoughts ? Cheers :)

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

    Hello Charles,
    Thanks for the tutorial.
    What version of Unity does this work best in?
    I imported your project's package into Unity 2020.3.32f1 but the numbers on the keypad are missing and the textures on the walls/doors don't look the same as in the video.
    Thanks!

  • @quocvnguyen7117
    @quocvnguyen7117 3 ปีที่แล้ว

    I love it. Helpful and peaceful.

  • @sigmundurjohansen7166
    @sigmundurjohansen7166 4 ปีที่แล้ว

    OMG this was so silly, yet so effective! haha genius!

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

    Good stuff man! Im down to be a person in your videos if you need anyone.

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

    Near the start of the video you discounted having a coupling to the door class. Does an event like this not still create the same class coupling anyway??

    • @mrgscreen6541
      @mrgscreen6541 4 ปีที่แล้ว

      Yee man, you're right, it's coupling. As I understood, to decouple things in a similar way try to use broadcast messenger
      wiki.unity3d.com/index.php/CSharpMessenger_Extended
      but it's not integrated in unity, unfortunately

  • @davidpage9241
    @davidpage9241 4 ปีที่แล้ว

    It's like when my rubber ducky talks back to me!

  • @mufelo
    @mufelo 4 ปีที่แล้ว

    Hey, any chance you could make a video about using events in ECS. I have found some methods that feel a bit like work arounds and I have built eventqueues myself using NativeQueue but not sure what the best practices are for keeping things thread safe. I have not ran into any huge problems with concurrency yet but I havent built anything bigger either.

  • @MQNGameDev
    @MQNGameDev 4 ปีที่แล้ว

    Thanks for the cool video. I love using C# events but I often run into an issue where the subscriber tries to subscribe to the event before Unity has Started the GameObject that holds the event. Any tips on how to avoid the issue? I know I could go into my project settings and adjust the Execution order but it feels like more of a hack than a solution and often leads to other issues.

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

    so objects that are attached to and interact with an object should be a subclass of the object they interact with?

  • @gegenton3953
    @gegenton3953 4 ปีที่แล้ว

    Having watched both C# Events and UnityEvents videos, I'm having an issue with operations that need to run in Update() but listen to specific events. For specific reasons I want my character to lerp (that can only run in Update?) based on Events that are triggered from a User Input class. However you can only reference a method (e. g. MoveRight()) as a listener in the UnityEvents list for "InputRight". I currently have a workaround with a bool set to true in the MoveRight() function that the update function has as an input for an if-clause. But this looks very ugly and can't be right.
    Any ideas on how to solve this (other than creating a single class for all different types of movement and referencing the update method)?
    Love your videos, very "explaining", rather than "telling"!

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

    Love that style! :D

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

    I don't understand why he created the KeypadDoor subclass instead of subscribe the event directly from the Door superclass.

  • @RohitSharma-vq2gn
    @RohitSharma-vq2gn 2 ปีที่แล้ว

    I feel indebted :)

  • @darkman237
    @darkman237 3 ปีที่แล้ว

    In the keypaddoor class, wouldn't you use OnEnable and OnDisable?

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

      Yeah, that tends to be the best practice. Honestly though, if the object isn't being disabled and then re-enabled it doesn't make much of a difference.

  • @rani600
    @rani600 4 ปีที่แล้ว +9

    What do you guys feel on actions instead of delegates? easier to make events that way in my opinion, and feels much cleaner in a scaleable project, instead of each time to create a delegate, Great video as always btw!!

    • @rani600
      @rani600 4 ปีที่แล้ว

      @@bezoro-personal I guess it depends on how you view, if you name the action properly, it's seems much clearer then delegates.

    • @CSPlayerDamon
      @CSPlayerDamon 4 ปีที่แล้ว +5

      Actions are delegates as well. They don't scale as well though. Imagine having 20+ events and 100+ variables that you defined as Action. Somewhere down the line you decide that must be Action instead. Now you have to go change those 20 definitions and 100 variables to Action. If you had defined a delegate, though, you'd only need to modify the delegate. That, though, doesn't help you from having to change all the code you wrote to use a string instead of int.
      Events only scale well if you're sure or close to being sure what the event is for. In general, using an interface or a delegate scales better than Action or Func. Lastly, if you're too unsure on what parameters the delegate / action should have, you could make a class / struct for the parameter and populate the class. That way your code will break only if you change the return type or change the class data. You should avoid that, though, and focus on describing the event as best as you can.

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

      @@bezoro-personal Situations like that are mostly found in event-heavy applications, i.e turn-based games, low level networking, retained-mode UIs (like the new UI from Unity), etc...
      The new Unity UIElements is a mighty example of that thought process. It uses a generic RegisterCallback to handle registering of events, where the generic type may be a completely different event every time. Check it out if you have the time!

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

    Very cool. Way over my head. Haha

  • @dennisgonzales9521
    @dennisgonzales9521 4 ปีที่แล้ว +7

    A more shorter way of creating an event
    public event Action EventName();
    remember to use the namespace
    using System;

    • @capsey_
      @capsey_ 3 ปีที่แล้ว

      Is there a difference between using Action and custom delegate? I know that Action is just a delegate that already defined in System, but is there a drawback to use Action instead of delegate?

  • @robertkadrgulov6615
    @robertkadrgulov6615 4 ปีที่แล้ว

    Hi, dude, what keyboard do you use? what do you call a mointor

  • @darkman237
    @darkman237 3 ปีที่แล้ว

    What if you wanted to keep all your delegates in one place? A master script?

  • @chris.davidoff
    @chris.davidoff 4 ปีที่แล้ว

    Stoked to see this! I do the exact same thing for my inventory's UI updates.
    Some people talk about performance use of events.. I'd love to see numbers on directly calling a function vs one getting called through an event.
    To give a ball park, I think a C# event will take ~ 50ms for 10 million invokes based on this reddit: www.reddit.com/r/Unity3D/comments/35oekm/delegate_events_vs_unityevent_which_one_is/

  • @FlaurensLBO
    @FlaurensLBO 4 ปีที่แล้ว

    Great video as always.
    I have a question: Is it important to call Unlock.Invoke()? I normally call Unlock()...

  • @vaporalight3670
    @vaporalight3670 3 ปีที่แล้ว

    At 1:24, What is Type Coupling?

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

    The ?. Operator blew my mind

  • @diegoduarte187
    @diegoduarte187 4 ปีที่แล้ว

    Good video, what kind of keyboard do you have?

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

    What theme and font was at 1:55 ?

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

    My music major ass just thinks of the note C# lol

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

    You do a funny theater talking to yourself. Love it. Keep the great work up bro!
    for(;;) { likeButton = IsSourceCodeOpen(); }
    Even if I were your patron would be glad you share the code with anyone.

  • @StefanLopuszanski
    @StefanLopuszanski 4 ปีที่แล้ว

    By the way, your link to Editor Console Pro is the same as your Rainbow Folders 2 link :-P

  • @cubasia16222
    @cubasia16222 4 ปีที่แล้ว

    But what if you have 10 doors and 10 keypad ? You need 10 subclass? And what if the number of door in the room is generated randomly ?

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

      No, you don't need to create KeypadDoor1, KeypadDoor2, etc for each of your door. You simply add KeypadDoor script to each of your door objects and your desired keypad to the KeypadDoor of each door.

  • @caithid1951
    @caithid1951 3 ปีที่แล้ว

    I hope I can get helped by myself when I stuck at my code.

  • @r3s3tme
    @r3s3tme 4 ปีที่แล้ว

    Why not system.action = delegate?
    Less code no null check

  • @dknighter2
    @dknighter2 4 ปีที่แล้ว

    Are C# Events better then using UnityEvents?

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

    I have watched tons of videos on this and none of it works for me. No matter what I keep getting the same null object reference error at runtime. Everyone says it's so simple and wonderful, but I must be the only idiot not getting it. It's as if no matter what I do, I cannot subscribe to an event in another class. It doesn't matter if I use UnityEvents or C# events.

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

    ****SCREAMS IN SKYPE****

  • @subliminalcastillo2126
    @subliminalcastillo2126 3 ปีที่แล้ว

    Ride is available for free if you use their early access version!
    > www.jetbrains.com/rider/nextversion/
    I found this out last night after quitting rider for a month due to financial reasons. This has changed the game for me, as I love rider to death, but just can't afford it right now.
    Spreading the message around on youtube.

  • @alisayah5397
    @alisayah5397 4 ปีที่แล้ว

    name IDE ur using ?

  • @MrStonedLover
    @MrStonedLover 4 ปีที่แล้ว

    Where is the diffrent between Events and Action from c# ?

    • @MrStonedLover
      @MrStonedLover 4 ปีที่แล้ว

      @@bezoro-personal nice cause I use it in the past and just wounder where the difference is :D

  • @josh_swanson
    @josh_swanson 4 ปีที่แล้ว

    !!Link error in description:
    Editor Console Pro links to Rainbow Folders 2

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

    Back to talking to himself again. :feelsbad:

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

      I have to talk to SOMEONE during this quarantine 😂

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

    I want to FaceTime this man

  • @scififan698
    @scififan698 3 ปีที่แล้ว

    it's 2020 and you're still using delegates? hmmm.

  • @TheSpacecraftX
    @TheSpacecraftX 4 ปีที่แล้ว

    Feels weird calling Door a subclass. It's a base class. If anything, intuitively, any class that inherits from it would be the subclass.

  • @jackliu8991
    @jackliu8991 3 ปีที่แล้ว

    great content, but it reminds me of porn acting haha

  • @SHOOTINGDNA
    @SHOOTINGDNA 4 ปีที่แล้ว

    XD

  • @lapineagaric134
    @lapineagaric134 4 ปีที่แล้ว

    who still uses skype? @.@

  • @thePocketWatch45
    @thePocketWatch45 4 ปีที่แล้ว

    bro i love your channel....