How To INTERACT with Game Objects using UNITY EVENTS Tutorial

Поділитися
Вставка
  • Опубліковано 31 січ 2020
  • Interacting with GameObjects within your scenes is a core tenet to game development within the Unity Engine. I wanted to engineer a system that would show off Unity Events, while also being generic enough to slap on to any of your objects and wire up quickly.
    Admittedly there are many ways to improve upon the basics I show in the video (as well as lots of error checking and handling!), but I wanted to demonstrate the concept in a concise and timely manner.
    I'm confident this can be a useful launching point, and I hope you'll find it useful!
    ✨Want to support the channel?
    Buy me a coffee ☕: ko-fi.com/bmoli
    LIKE the video if this helped you out at all, it helps the channel's visibility and lets me know what I got right!
    COMMENT if you have any suggestions or critiques! (or just want to say hi)
    SUBSCRIBE for more tutorials and game development content!
    Thanks for watching!!
    MORE UNITY TUTORIALS (PLAYLIST): • Epic Unity Tutorials
    SOUND EFFECT TUTORIAL MENTIONED: • Improve every SOUND EF...
    NEW to game development? Start with my 2D Movement Tutorial: • 2D Side Scroller MOVEM...
    ~~~~~~~~~~~
    ASSET LIST
    ~~~~~~~~~~~
    Ninja Character: assetstore.unity.com/packages...
    ~~~~~~~~~~~
    #bmo #unity #tutorial

КОМЕНТАРІ • 102

  • @Daniel-qt5ib
    @Daniel-qt5ib 4 роки тому +19

    Thank you so much! I haven't used Unity Events much before but they're perfect for things like this. Well explained too X)

  • @MC-yo6kz
    @MC-yo6kz Рік тому

    This helped me clean up my old door system to something way better and more flexible. Thank you

  • @joaquin.galvan
    @joaquin.galvan 4 роки тому +26

    Dude you just saved my ass, keep on going you're great, YT need more tutorials like yours

    • @BMoDev
      @BMoDev  4 роки тому +5

      Thanks, I really appreciate hearing that!

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

    Thanks for this Awesome Tutorial it helped me immensely with my project that I'm building atm only for learning by doing

  • @ilyasformuli.2779
    @ilyasformuli.2779 Рік тому

    I feel like I've struck gold with this video. Amazing tutorial!

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

    Again another dope tutorial, it clarified a lot how Unity Events work, thanks!

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

    THE BEST tutorial on youtube for unity interactions! ty!

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

    Great video. Good content.
    You deserve alot more subs.

  • @olivertom1
    @olivertom1 3 роки тому +4

    Me: Hmmm does video have the info I want?
    Intro: Yes exactly what you want!
    Thank you for showing what you are doing at the start so I didn't have to watch half the video to find out!

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

    Wow, this just ease a lot the script. My codes were loaded of GetComponents because i didn't know how to use this function

  • @baby-sheesh
    @baby-sheesh Рік тому

    really good explanation! thank you

  • @cinemacat4108
    @cinemacat4108 3 роки тому

    Thank you very much you helped me a lot

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

    Oh wow thank you so much!!

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

    very good tutorial. thank you

  • @xmahopabuse8501
    @xmahopabuse8501 4 роки тому +1

    The video was very helpful, thank you.

    • @BMoDev
      @BMoDev  4 роки тому

      Glad I could help!

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

    This is awesome!

  • @yousifsuleiman7613
    @yousifsuleiman7613 4 роки тому

    I am so happy for finding an awsome channal 😍

    • @BMoDev
      @BMoDev  4 роки тому

      The feeling is mutual!

  • @cognusjohn1269
    @cognusjohn1269 4 роки тому

    This is awesome thank you!!

    • @BMoDev
      @BMoDev  4 роки тому

      You're awesome, hope it helps!

  • @scratchy996
    @scratchy996 3 роки тому +5

    Came for the title, stayed for the duck.

  • @gi6624
    @gi6624 3 роки тому +1

    Thank you so much you saved my game

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

      Thanks, but you put in the work! 🙏 Good luck, would love to see your game!

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

    amazing tutorial

  • @robbercool
    @robbercool 3 роки тому +1

    Awsome video man!

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

      Thank you, friend

  • @tomasbeno1593
    @tomasbeno1593 3 роки тому +1

    i have a prolem with eventsystem, i have 2 scenes (MainMenu , Game) . Event system as an object is in MainMenu scene (like in hierarchy) , but when i laod scene "Game" , buttons in the "Game" are not working. If i swap EventSystem to the scene Game , it works , but then when i go back to "MainMenu" , the buttons do not work there. Unity says i can have only one EventSystem, so how does it work? How can i "share" eventSystem for whole project , or all scenes ? thank you

  • @gistypical
    @gistypical 3 роки тому

    You are a god.

  • @yoko2579
    @yoko2579 4 роки тому

    OMG Thank u very much!

  • @durrium
    @durrium 3 роки тому +1

    Very nice! When we want to close the chest? How would we do it :D

  • @18vlsnp
    @18vlsnp 2 роки тому

    This is exactly what iv been looking BUT unfortunately my unity is an older version, gna have to use normal events instead of Unity Events? :(

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

    What if you have two chests close by both in range? How do you make sure only one opens if you click the interact key?

  • @Fabian-bx2ci
    @Fabian-bx2ci 2 роки тому +1

    What did you did in the animator from the chest?

  • @BoomBunny
    @BoomBunny 4 роки тому +1

    This helped so much xD Thank youuuu! Also is it possible to change the Interact keycode within another event?

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

      Awesome! Yeah definitely, you'd just have to change the variable Keycode

  • @revmatch6r
    @revmatch6r 4 роки тому +1

    Awesome vid!! Quick question tho - what happens if there's 2 intractable circles that overlap? Is there any way to say that one should be interacted with over the other?

    • @BMoDev
      @BMoDev  4 роки тому +4

      Right now, in the current state of this video it would trigger both of them. There is absolutely a way to prioritize (conceptually, you could queue them and execute one by one, or by some other factor like distance to the player), but in terms of implementation - that would be a larger discussion. This is more just a feature starter to understand the concept.

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

    Was that like a giant yoyo?? (Duncan yoyo). Thanks for the info btw :)

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

    im trying to make a player "cursor" to be able to interact with the objects, i followed every step to the near exact dot, exept names of objects and a few variables and it wont interact, what do i do?

  • @tbprod5
    @tbprod5 3 роки тому

    If I’m making a 3D game do I change the trigger code to enter 3D and collider2d to 3D? Thanks, showbiz pizza fan 101

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

    I watched your dialogue box tutorial as well, is there a way to combine it so that it plays the script with a interaction?

    • @Its_Noctis
      @Its_Noctis 6 місяців тому

      i know you left the comment a year ago, but have you found a way to make it work? i am a bit stuck myself...

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

    What must i do if i want this for 3d project work?

  • @bladeinferioryt
    @bladeinferioryt 3 роки тому

    hi i was wondering how you referenced your notification in vs i tried obj = GetComponent(); (ring is the name of the image) and i have already defined public GameObject obj but it says the type or namespace ‘Ring’ couldn’t be found

    • @jamespope5668
      @jamespope5668 3 роки тому

      You put the class in the carrot brackets. So for instance if you wanted to find the script he made in this video you'd type obj = GetComponent();
      Are you trying to get a specific image file? Because GetComponent(); can only be used on scripts that inherit from Monobehaviour

  • @markoviik3324
    @markoviik3324 3 роки тому

    What about 3d game? do i still use 2dcollider?

  • @jakeduncan2721
    @jakeduncan2721 4 роки тому

    Hey BMo sweet vid - Know any open source 3d sprites / libraries to mess around with some simple simulations? I'd love to see that

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

      Hmm, what kind of simulations? There are alot of libraries out there (unity asset store would be my first look)

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

    i bad at code so i look at your and try to learn something. WHenever i copy Unity Event as same as your. It appear this.
    "The type or namespace name 'UnityEvent' could not be found (are you missing a using directive or an assembly reference?)"

  • @keeleon
    @keeleon 4 роки тому +1

    How do you toggle the sprite between open and closed? I created a single sprite animation in the animator and it kind of works, but it doesnt toggle with the checkbox like yours does.

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

      I'd look up how to change Animation state in Unity. I'll eventually make a video on this.
      Basically you need to make a bool variable in the animator (not in script). Setup transitions between open/close animations and use the animation bool to determine how it transitions. Then in a script, when you interact, change the objects animation bool.
      It's a lot to cover in a comment, but that is the general idea. There are many resources out there that cover animation transitions. You can do it, good luck! :)

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

      @@BMoDev Can you explain more, like i need to know

  • @Asdzxc120
    @Asdzxc120 3 роки тому

    can you make a video on how did you make the ninja move with animation haha i really need it

  • @williamallen6382
    @williamallen6382 3 роки тому

    How do you create the ! pop-up when the character is near an interactable objects?

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

      In this video my setup was I had the "!" sprite set as a child GameObject to my player (defaulted to inactive). I gave my interactables a CircleCollider2D trigger, and when the player enters this it sets the "!" GameObject to active.

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

    Thanks a lot man. Btw i have a question, do these colliders have an effect on the game's performance? Would it be better to have every object to detect the player and an input, or is it better for the player to have a collider that looks for objects?

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

      Well even if your player drives collision detection the objects still need some collider as well for the player to detect if they're close enough to interact with...
      To answer you from a more general standpoint, collision can get pretty computationally expensive, but it really depends... If you're targeting mobile or something where performance is stricter than say PC or if you have thousands of objects with colliders then it'd be worth it to take the approach to minimize that... but if you have like 20-30 colliders in a scene its really not something to get hung up on

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

      @@BMoDev thanks man

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

    Hey BMo Thanks so much for the tutorial! I have a shop UI that pops up when I interact with an npc but I want it to close when I either press E again, or when I leave the range. I'm a little lost on this and was hoping for some help. Thanks so much in advance!

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

      Checkout my gameover or pause menu videos, similar concept!

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

      @@BMoDev Cool, Will do! Thank you!

  • @Tide_Wolfia
    @Tide_Wolfia 4 роки тому

    so I am trying to make it run an animation but it is looping at the very beginning how would I fix this?

    • @BMoDev
      @BMoDev  4 роки тому

      I think its tough to say without knowing your project, but my guess is you are repeatedly triggering the animation to play, so it just keeps restarting.

  • @fungusguy
    @fungusguy 4 роки тому +2

    Hey when I saved the first bit of script you did it says it doesnt recognize "UnityEvent" I'm sure it's something on my end but any help?

    • @bensmart2829
      @bensmart2829 4 роки тому +2

      did you have using UnityEngine.Events; at the top of your script?

    • @fungusguy
      @fungusguy 4 роки тому +1

      @@bensmart2829 thanks yes I did I figured it out but thanks for the help :)

    • @cabbagemontage6999
      @cabbagemontage6999 3 роки тому

      @@bensmart2829 Fixed that problem for me, but it still has an issue where it does not recognize "KeyCode"

  • @jainyash900
    @jainyash900 3 роки тому +1

    When I press check in the "Is open" for the chest my chest animation does not work. Any solutions?

  • @cabbagemontage6999
    @cabbagemontage6999 3 роки тому +1

    I have a question - What if two interactables are too close to each other, and I just want the player to activate one of them, and not both at the same time?
    Like, if the player enters both the collider of a box and a door at the same time, and for gameplay reasons, the things are close to each other... How can I make him only interact with one?

    • @evikingg5262
      @evikingg5262 3 роки тому +1

      Maybe make some sort of rotating a character in the game, and when player is rotated right, you(for ex.) open right chest, but if he's rotated left open the left chest. But I don't know how to code it...

    • @cabbagemontage6999
      @cabbagemontage6999 3 роки тому

      I ended up doing something different :
      Since I'm doing a top-down game, I can attach qualities to the pointer...
      I still needed the Collider for the animation though.
      So, my solution was to create a separate collider that is activatable when the pointer hovers over it - The pointer itself is another object attached to the mouse cursor... So, I gave it a rigidbody, the tag "pointer", and when it hovers over the collider, it makes the colider for the animation/action activatable - only when the pointer hovers over it.
      When the "take" animation starts, it deactivates the other collider, so that it won't bother with the animation process.
      If I were doing a side scroller... I think the rotation could work, but, what if someone wants to first take something specific?
      without the mouse cursor... Perhaps it could bring up a wheel that holds every interactable item in a small radious, and you can select from it which one to take.
      No idea as for the code, but, selection through a small menu if there are >1 colliders in radious sounds reasonable.

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

    Thanks but u missed the BoxCollider2D for the player..

  • @TheAstronomyGame
    @TheAstronomyGame 4 роки тому +1

    This is a very good tutorial, but I am encountering a problem. For my interactAction, I have a change scene script. However, whenever I try to use it, I get the error “ArgumentException; object of type ‘UnityEnginge.object’ cannot be converted to ‘UnityEnginge.Collider2D’. I have ‘Collider2D’ in the parenthesis of my interactAction. Any advice would be really appreciated.

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

      You misspelled UnityEngine

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

      You put "UnityEnginge"

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

    I don't get how the chest changes to being open when executed, is there something that I missed?

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

      No, I don't explicitly cover it, but I do quickly show the script for what its doing. Basically the chest just has 2 animation states, closed and open, and interacting with the chest is toggling that animation change.

  • @molyporph1045
    @molyporph1045 3 роки тому

    Super dumb question, but how did u make running left animation for this character model, not sure if I'm using wrong version of it or there is simple way to implement that.

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

      You can checkout my 2D Sidescroller Movement tutorial where I show in code how to do it, but basically you just flip your player sprites. You re-use the same animation in one direction it just mirrors in the opposite.
      Very quick to do.

    • @molyporph1045
      @molyporph1045 3 роки тому

      @@BMoDev Thank you for your answer, yeh that was super quick.
      Got another question, for which I cannot find answer somehow... I'm trying to make some kind of Among Us copy.. i cannot find an answer how to reload my MiniGame Scene (when u die in it or w.e) without reloading my MainGame scene(i dont want position of my character or task bar to change) which is working in background additively..

    • @molyporph1045
      @molyporph1045 3 роки тому

      Nvm found one i think, finally :) how to make singletone of class, which i will apply to player and make new object for score and do it the same i guess..
      Now the only problem i have is how to open a scene in pop up window in front of main game, i'm thinking it has to do Camera views probably :)

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

    finally i figure out the the closing.
    here if u want to open and close.
    public bool isOpen;
    public Animator animator;
    public void LeverControl()
    {
    if (!isOpen)
    {
    isOpen = true;
    Debug.Log("Lever is now Down");
    animator.SetBool("isOpen", true);
    }
    else if (isOpen)
    {
    isOpen = false;
    Debug.Log("Lever is now Up");
    animator.SetBool("isOpen", false);
    }
    }
    *on Unity Animator when creating animation u have to add bool onto the parameters. isOpen. when checked means true and when unchecked means false.
    i hope i helped somehow, Im also a beginner.

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

    how to close that door?

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

    When I used the UnityEvent it gave me an error

  • @kiddowhy1105
    @kiddowhy1105 4 роки тому

    sweet

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

    My version of Unity 3.6.0 doesn’t recognise UnityEvent as a variable type, has it changed?

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

      Hi I think Unity 3.6.0 is your Unity Hub version, I think you should be looking at the editor version (e.g. 2022.3.11f1) and something is not working for me too can you let me know if you made it work. For me it only detects when im NOT in range. tnx

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

      @@josipbroztito8005 I managed to figure it out like a few minutes after I posted that comment lol. Mak sure you include unityevents in your libraries, then the variable type should be okay.

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

    how i can get animator chest assets?

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

      I made them myself in photoshop, tbh I'm not sure if I even have them anymore

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

    Input.GetKeyDown doesn't work...Unity says Imput doesn't have GetKeyDown

  • @drioko
    @drioko 3 роки тому +1

    "keeping things simple"

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

    maybe, just you could use interfaces, i would do it that way

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

    Tried following this in 2024 but there is no Interact Key (2:10) anymore so i think this guide is outdated.

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

    it would've been nice if you also explained how to close the chest box.
    ever single time we ask how to open boxes we also want to know how to close.
    or how to drive a car forward we would definitely want to learn how to make it go backwards.
    or when i pick something up and carry it around, would also want to know how to drop it.
    common sense dude.
    pisses me off that i have to go around and figure out how to make isOpen false.

  • @ReyBanYAHUAH
    @ReyBanYAHUAH 3 роки тому

    Always remember to repent of your sins (sin is transgression of YAHUAH’S LAW: Genesis, Exodus, Leviticus, Numbers, & Deuteronomy) And Have Belief On YAHUSHA HAMASHYACH. HE Died and Rose Again On The Third Day So that you can be forgiven of your sins!
    HE Loves you! Come to HIM! :) :) :) :) :) :) :) :)