Spare Your Pain Using UNITY EVENTS Tutorial

Поділитися
Вставка
  • Опубліковано 3 бер 2022
  • Programming in general leads to a lot of spaghetti or highly coupled code, ridden with depencies - but for some reason Unity makes this even easier to do. Especially among new developers.
    In this Unity Tutorial learn how to utilize Unity Events to easily handle many cases in your games instead of passing around GameObjects and ruining your project.
    ✨Want to support the channel?
    Buy me a coffee ☕: ko-fi.com/bmoli
    ➤SUBSCRIBE TO MAKE GAMES AND BECOME BEZOS RICH
    ➤LIKE the video if you enjoyed, it really helps the channel!
    ➤Join our DISCORD SERVER: / discord
    We have channels to help you with your problems!
    Thanks for watching!
    #bmo #unity #tutorial

КОМЕНТАРІ • 74

  • @anttiv7109
    @anttiv7109 10 місяців тому +4

    I can't believe I had to go through like 10+ tutorials about events before I found the that explains it in a good way.

  • @OMGamingNL
    @OMGamingNL 2 роки тому +30

    This is something every new developer (like myself) should learn! I'll definitely be using this all the time now. Thank you for the amazing quality video!

  • @elysium2314
    @elysium2314 4 місяці тому +2

    What makes this tutorial stand out is that you are not trying to implement big game ideas but you stay on the level of the learner. Great job. Keep up the good work!

  • @madpenguin58
    @madpenguin58 2 роки тому +1

    This helped me so much! I am making a Pong game with a twist, and this helped me to get the Pong part of it done in 10 minutes! This is an absolutely amazing tutorial to watch and I am excited to watch the rest!

  • @Just_Poncho
    @Just_Poncho 2 роки тому +15

    I have made more than 10 projects and have been developing with unity for 2 years, AND IN ALL THIS TIME I DID NOT KNOW ABOUT THIS, thank you for uploading this video.

    • @BMoDev
      @BMoDev  2 роки тому +6

      You bet! I've used Unity for 10 years now and I still learn new things regularly haha

    • @rmt3589
      @rmt3589 Рік тому +1

      I only started last year. But I'm constantly watching videos on my phone so I can learn more. So when I'm at my computer, I have already curated information to learn from.
      (Now if I can just start going to bed before 4am. Lol)

    • @Just_Poncho
      @Just_Poncho Рік тому +4

      Update: I still think this is one of the most useful things that unity has to offer by a longshot I have developed countless systems like an interaction system and dialogue system with this method so thanks again

  • @Liberaven
    @Liberaven Рік тому

    Finally a SIMPLE demonstration of UnityEvents! This is so helpful. I can alreayd see how much easier so many of my systems can be. Thank you

  • @kurushimee
    @kurushimee 2 роки тому

    Damn I really don't understand how you're not yet exceptionally big, your channel is a real gold mine! Thanks for your tutorials!

  • @damianlord7954
    @damianlord7954 2 роки тому +23

    Nice tutorial. Personally I prefer C# Action 'events' to really decouple as each object could just implement a method when that event is triggered, and there's no need to hook them in directly. Unity Events seem better to me when you're doing multiple events on the same object, like steps effectively. Having a Unity Event run actions on different objects means you're still having to couple multiple objects in manually via the editor.

    • @niclasandreasen639
      @niclasandreasen639 7 місяців тому +2

      I agree, dragging gameobjects quickly becomes a mess. Also spawning new "enemies" would not have the correct setup. So it would end up being a null reference.

  • @megazord5696
    @megazord5696 19 днів тому

    Bro, you explain things so well, ty so much!

  • @awawa5594
    @awawa5594 9 місяців тому

    Ty for explaining so clearly to beginners, so many tutorials use fancy lines of code and it's so offputting to follow because it makes you feel so shit for not understanding. THANK YOUUU, SUPER HELPFUL

  • @BrandonNyman
    @BrandonNyman Рік тому

    Thank you. While i knew what these were and what these looked like, i was still unsure how and when to use them. Now i think i do and it is so much clearer.

  • @bloudy.x
    @bloudy.x Рік тому +1

    Thanks, I knew this before, but now it's becoming a way clearer.

  • @TinyCastleGames
    @TinyCastleGames Рік тому

    Great simple, clear video. Definitely using this on my next game.

  • @DoxX069
    @DoxX069 Рік тому +1

    I love your Videos, your explaining things so simple, keep it up

  • @rmt3589
    @rmt3589 Рік тому

    This is gonna help so much. It's the kind of thing I was wishing the code would do.
    Now, not as mind blowing as when I discovered dozenal, it's still made an explosion. Love discovering things that work like how I wish the world worked!

  • @Stompin40
    @Stompin40 2 роки тому +1

    Great video, once again delivering solid content!

  • @muhendisbibey
    @muhendisbibey 2 роки тому +2

    WOW! I should definitely use this. Thanks

  • @youtuberdepueblo6530
    @youtuberdepueblo6530 Рік тому

    Thank you so much! It's really well explained

  • @ErtBaran
    @ErtBaran 2 роки тому +2

    That is awesome. 💯 Thanks so much. It was so complex in my head. So i never checked for learn.

    • @BMoDev
      @BMoDev  2 роки тому +1

      Love to hear that

  • @maazmaaz97
    @maazmaaz97 10 місяців тому +1

    You use practical example for UNITY EVENTS, amazing guide.

  • @durrium
    @durrium 2 роки тому +8

    Wow thanks! This opened my eyes to creating more general scripting!

    • @durrium
      @durrium 2 роки тому

      Like the key script could change any text, and you could enter what text you want In the inspector :)

  • @regys9521
    @regys9521 2 роки тому

    Keep it simple is the KEY, thanks man

  • @mandamoon9149
    @mandamoon9149 2 роки тому +15

    No more spaghetti code!! This is such a great way to clean up code, appreciate the tips as always BMO!

  • @diegogomez87108
    @diegogomez87108 4 місяці тому

    I always hated unity for not having a good event system, Thank you for telling me about this and thank unity for implementing it

  • @eileeng2492
    @eileeng2492 2 роки тому +2

    This is helpful BMO
    Very useful

  • @deathgho
    @deathgho 2 роки тому +2

    Great video as always bless you

  • @superblue5871
    @superblue5871 Рік тому

    Awesome tutorial, thank you.

  • @jaxxrr
    @jaxxrr Рік тому

    4:00 i spent the last 3 hours on youtube looking for this info THANK YOU

  • @mertuzun8976
    @mertuzun8976 Рік тому

    great explaination! thank u!

  • @SmallHedgeHQ
    @SmallHedgeHQ 2 роки тому +1

    Bro you are a lifesaver!

  • @suicune2001
    @suicune2001 2 роки тому +2

    Interesting! I've never seen something like this before.

  • @evaunit0014
    @evaunit0014 Рік тому

    Reminds me of how much I used to use broadcast events in scratch back in the day.

  • @random_precision_software
    @random_precision_software 2 роки тому +1

    I will defo start using them now.

  • @64imma
    @64imma 26 днів тому

    I'll definitely be looking to use more events in my future projects. I barely touched events in the first game i tried making, and theres definitely a lot of spaghetti code in there, with having to reference multiple game objects in a script, as well as passing information across 3 or more scripts to get a desired outcome.

    • @64imma
      @64imma 26 днів тому

      I just implemented some events in this simple testing demo that I've created and just by incorporating some events, I've been able to completely abolish the need to pass references in any of the scripts I've passed.

  • @MaestroMarc
    @MaestroMarc Місяць тому

    Great video! Could you make one showing us how to make the next level button appear in a level menu scene after all waves of enemies are defeated in a game scene?

  • @tegomlee
    @tegomlee Рік тому

    Thanks for the tutorial

  • @suicune2001
    @suicune2001 3 місяці тому

    I'm working on a virtual pet game and I want there to be little icons above the pet's head when they want something. Events sounds like a perfect way to handle that!

  • @ZacMarvinGameDev
    @ZacMarvinGameDev 2 роки тому

    This great! Question though. If a key or rock object were removed from the scene or if the prefab were used in a scene without those objects would the event break because it can’t find the game objects and their attached scripts?

    • @Hietakissa
      @Hietakissa 2 роки тому +1

      I haven't watched the video and thus haven't seen the implementation he made, but you may want to have a static EventManager class that handles all events. If being able to subscribe events via the inspector is a deal breaker for you, you could instead use a Singleton EventManager.
      Collecting a key fires the KeyCollected method (not required, you could run the event directly, I find this way to be cleaner though), which then fires the OnKeyCollected event if there are subscribers for it. A door has subscribed that event and will run the associated method. If you want support for multiple keys and doors in the same scene, you could pass in an int ID with the event, and each door checks if that ID is the same as their own ID before opening.
      This way all different parts of the EventSystem are decoupled and won't cause errors if one of the pieces were to be missing.

  • @bsman321
    @bsman321 9 місяців тому

    good video!

  • @teliots
    @teliots Рік тому

    Do you always have to use the editor to assign what functions get run? What if the objects don't exist at the start of the game? I would much rather define all of that in code and avoid the editor entirely.

  • @svarei8997
    @svarei8997 10 місяців тому

    god damn, I just scrapped like 3 projects because of spaghetti code mad by those references over references

  •  Рік тому

    lmao the ending

  • @galberger3937
    @galberger3937 5 місяців тому

    Hi.
    How can i change the script instead of only one key, the player needs to find and pickup two or more keys?

  • @alfiandm5782
    @alfiandm5782 11 місяців тому

    omg i literally did reference al the time after 1 years learning , and dont know whats event system does :D

  • @zanagi
    @zanagi 11 місяців тому

    holy shit this is actually revolutionary lol

  • @user-od9gx8xd2j
    @user-od9gx8xd2j 2 роки тому

    thank you

  • @mcjgenius
    @mcjgenius 2 роки тому

    ty

  • @msmigs1173
    @msmigs1173 Рік тому

    So how do you pass in parameters?

  • @nilesderl8715
    @nilesderl8715 9 місяців тому

    ur so HANDSOME THANK YOU UR CHANNEL IS A LIFESAVER AS A SENIOR IN COLLEGE FOR GAME DEVELOPMENT I SALUTE YOU KIND SIR o7

  • @Just_Poncho
    @Just_Poncho 2 роки тому +1

    This seems like a great feature, and I think it is, but not for the reasons stated, if you want to avoid spaghetti code isn’t it easier to just go ahead and make everything private?

    • @BMoDev
      @BMoDev  2 роки тому +3

      Yep [SerializeField] tag with private is the "correct" way to do it, and make getters/setters... but to an audience that is very new to programming it can unneccesarily complicate what im trying to showcase (and has)

  • @danielnix3284
    @danielnix3284 Рік тому

    Game changer!

  • @nautisshadrick9254
    @nautisshadrick9254 Рік тому

    I am just curious, Why would a key help with moving a rock?
    lol Thanks for the tut

  • @SLthenus
    @SLthenus 3 місяці тому

    my bos say, he dont want us to make game using drag n drop from different game object. It's forbidden move in game developer

  • @user-ne1tf5to5h
    @user-ne1tf5to5h 2 роки тому

    wow..

  • @slowfuse
    @slowfuse 11 місяців тому

    6:10 I just don't see how this is particularly useful in the video example, you still need to put a hard reference to the object in the inspector or assign it as a listener via code. Either way there is still a hard reference being made, and it's not decoupled. So why not just put a hard reference to the monobehaviour instead of have an event trigger that monobehaviour? There is just less abstraction and less extra steps. What am I missing?

    • @magicalmusictv919
      @magicalmusictv919 10 місяців тому

      Your are right, there is still the need to drag in the references to the Event on the GameObject. A solution ive done recently is to do all my checking on the collision.
      I check if they thing ive collided with is the right kind of gameobject, and if the Key script is not Null on the Gameobject ill call the functions then. It may be less performant, but Its decoupled. Its like if Player collides with tag key, pickup key, if key collides with tag door, if door has unlock script, unlock door.

  • @LeGaLiZeDOOMz
    @LeGaLiZeDOOMz Рік тому

    not working at all

  • @T3QN1Q
    @T3QN1Q 2 роки тому +2

    yummy yummy yummy i have love in my tummy

  • @godzillakingkongvenom
    @godzillakingkongvenom 2 роки тому

    Keys

  • @bdenix1997
    @bdenix1997 2 роки тому +2

    anyways lets say you have a rock that has an id. and player has an id too.
    lets say you need to change the player's id to the rock's.
    either way you going to have to make the event reference both player and the rock. because you want to know both values. what you're doing here is just making some function run without passing any data or receiving. if anyone runs into problem where they want to make REAL interactions, they are going to have to reference those both scripts anyways. or on player script you just reference the interactable object. or if its not going to run every frame, just get component that class and do things. this video is just shallow.

    • @slowfuse
      @slowfuse 11 місяців тому

      thank you yes, I thought I was going crazy. I think the content creator and audience might be actually retarded

  • @BigKevSexyMan
    @BigKevSexyMan Рік тому +1

    I kind of wish there was a "New Method" option in that drop down.