Spare Your Pain Using UNITY EVENTS Tutorial

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
    @anttiv710910 ай бұрын

    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.

  • @elysium2314
    @elysium23144 ай бұрын

    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!

  • @OMGamingNL
    @OMGamingNL2 жыл бұрын

    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!

  • @Just_Poncho
    @Just_Poncho2 жыл бұрын

    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 жыл бұрын

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

  • @rmt3589

    @rmt3589

    Жыл бұрын

    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

    Жыл бұрын

    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

  • @damianlord7954
    @damianlord79542 жыл бұрын

    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

    8 ай бұрын

    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.

  • @diegogomez87108
    @diegogomez871085 ай бұрын

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

  • @madpenguin58
    @madpenguin582 жыл бұрын

    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!

  • @kurushimee
    @kurushimee2 жыл бұрын

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

  • @mandamoon9149
    @mandamoon91492 жыл бұрын

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

  • @megazord5696
    @megazord5696Ай бұрын

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

  • @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

  • @bloudy.x
    @bloudy.x Жыл бұрын

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

  • @awawa5594
    @awawa559410 ай бұрын

    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.

  • @muhendisbibey
    @muhendisbibey2 жыл бұрын

    WOW! I should definitely use this. Thanks

  • @durrium
    @durrium2 жыл бұрын

    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 :)

  • @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!

  • @TinyCastleGames
    @TinyCastleGames Жыл бұрын

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

  • @maazmaaz97
    @maazmaaz9711 ай бұрын

    You use practical example for UNITY EVENTS, amazing guide.

  • @Stompin40
    @Stompin402 жыл бұрын

    Great video, once again delivering solid content!

  • @DoxX069
    @DoxX069 Жыл бұрын

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

  • @jaxxrr
    @jaxxrr2 жыл бұрын

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

  • @eileeng2492
    @eileeng24922 жыл бұрын

    This is helpful BMO Very useful

  • @youtuberdepueblo6530
    @youtuberdepueblo6530 Жыл бұрын

    Thank you so much! It's really well explained

  • @regys9521
    @regys95212 жыл бұрын

    Keep it simple is the KEY, thanks man

  • @ErtBaran
    @ErtBaran2 жыл бұрын

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

  • @BMoDev

    @BMoDev

    2 жыл бұрын

    Love to hear that

  • @suicune2001
    @suicune20012 жыл бұрын

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

  • @deathgho
    @deathgho2 жыл бұрын

    Great video as always bless you

  • @SmallHedgeHQ
    @SmallHedgeHQ2 жыл бұрын

    Bro you are a lifesaver!

  • @superblue5871
    @superblue5871 Жыл бұрын

    Awesome tutorial, thank you.

  • @random_precision_software
    @random_precision_software2 жыл бұрын

    I will defo start using them now.

  • @64imma
    @64immaАй бұрын

    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

    Ай бұрын

    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.

  • @suicune2001
    @suicune20013 ай бұрын

    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!

  • @evaunit0014
    @evaunit0014 Жыл бұрын

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

  • @tegomlee
    @tegomlee Жыл бұрын

    Thanks for the tutorial

  • @BMoDev

    @BMoDev

    Жыл бұрын

    You bet

  • @zanagi
    @zanagi Жыл бұрын

    holy shit this is actually revolutionary lol

  • @svarei8997
    @svarei899711 ай бұрын

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

  • @bsman321
    @bsman3219 ай бұрын

    good video!

  • @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?

  • Жыл бұрын

    lmao the ending

  • @user-od9gx8xd2j
    @user-od9gx8xd2j2 жыл бұрын

    thank you

  • @alfiandm5782
    @alfiandm578211 ай бұрын

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

  • @ZacMarvinGameDev
    @ZacMarvinGameDev2 жыл бұрын

    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 жыл бұрын

    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.

  • @mcjgenius
    @mcjgenius2 жыл бұрын

    ty

  • @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.

  • @galberger3937
    @galberger39376 ай бұрын

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

  • @nilesderl8715
    @nilesderl871510 ай бұрын

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

  • @campiinz
    @campiinz10 күн бұрын

    Why getting a reference to the text component each time you increment the key count instead of just once at Start?

  • @Just_Poncho
    @Just_Poncho2 жыл бұрын

    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 жыл бұрын

    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!

  • @msmigs1173
    @msmigs1173 Жыл бұрын

    So how do you pass in parameters?

  • @SLthenus
    @SLthenus4 ай бұрын

    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

  • @nautisshadrick9254
    @nautisshadrick9254 Жыл бұрын

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

  • @BMoDev

    @BMoDev

    Жыл бұрын

    Gotta trust the science on this one

  • @nautisshadrick9254

    @nautisshadrick9254

    Жыл бұрын

    @@BMoDev xD

  • @slowfuse
    @slowfuse Жыл бұрын

    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

    11 ай бұрын

    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.

  • @T3QN1Q
    @T3QN1Q2 жыл бұрын

    yummy yummy yummy i have love in my tummy

  • @user-ne1tf5to5h
    @user-ne1tf5to5h2 жыл бұрын

    wow..

  • @bdenix1997
    @bdenix19972 жыл бұрын

    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

    Жыл бұрын

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

  • @LeGaLiZeDOOMz
    @LeGaLiZeDOOMz Жыл бұрын

    not working at all

  • @godzillakingkongvenom
    @godzillakingkongvenom2 жыл бұрын

    Keys

  • @BigKevSexyMan
    @BigKevSexyMan Жыл бұрын

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