how to use Unity's animation events ✨sync effects with footsteps

Sdílet
Vložit
  • čas přidán 12. 09. 2024
  • This is another little Unity engine tutorial about how to use animation events! They can be used for all kinds of things, but in this video I show how to use animation events to sync up an effect (a particle effect or a sound, maybe) with a character's footsteps. You can use this to create little puffs of dust, or a stepping sound, or even something more advanced.
    🦑 Where am I?
    website: www.savallion.com
    sticker shop: www.savallion....
    watch on Twitch: / savallion
    peep my insta: / thesavallion
    Read me on Medium: / lysscreative
    Learn from me on Skillshare: www.skillshare...
    ☕ ko-fi.com/sava...
    If you liked this, you can support me by watching more of my videos, hanging out with me on Twitch, or buying me a kofi coffee at the link above

Komentáře • 30

  • @Marble_Dreams
    @Marble_Dreams Před měsícem

    I sure will use this trick in my next video. Thank you so much!

  • @MrRevsRs
    @MrRevsRs Před rokem +1

    Great video! My run animation and footstep sounds are now synced up perfectly

  • @ivancarranza2473
    @ivancarranza2473 Před měsícem

    Wow. Great tutorial. Thanks so much!

  • @HangryAnimalsGame
    @HangryAnimalsGame Před 9 měsíci +1

    Thanks for this! you're right, there aren't many resources out there for this kind of nuanced explanation. This saved me a days worth of researching and random forums with so many a false result. Event Chat GPT fell short.. thankfully :P Liking the content!

    • @Savallion
      @Savallion  Před 9 měsíci

      You're welcome! I'm glad it helped.

  • @jzeltman
    @jzeltman Před měsícem

    Great tutorial. Thanks!

  • @sopinha-games
    @sopinha-games Před 5 měsíci

    Thank you so much. That was awesome, so well explained.

  • @jhancarloscelimaldonado3793
    @jhancarloscelimaldonado3793 Před 3 měsíci

    I really where needing this video, thanks you

  • @rackneh
    @rackneh Před rokem +1

    Great tutorial!

  • @MrKiraBR
    @MrKiraBR Před 6 měsíci

    Great tutorial, thank you so much!

  • @megupets
    @megupets Před rokem +1

    Awesome tutorial. Seems very simple.
    If I wanted to assign different sounds for footsteps, do example.
    Walk on grass sound
    Walk on dirt sound
    Walk on wood sound
    Is it a similar process?

    • @Savallion
      @Savallion  Před rokem +2

      It is a similar process, but you'll need another code piece to tell your animation event *which* sound it should play based on the position. I have seen some people use a texture to store the material of the terrain at every position, and look up the material from that texture. I have not done it myself but that is probably how I would try it first if I was going to add this feature.
      However you handle the terrain material lookup, in your animation event you will want to get the position of either the foot bone GameObject or the player transform itself, use that position with the code I mentioned to figure out which material you're stepping on, and then play the correct sound. You can save references to the foot bone or player transform the same way as we are saving references to the particle systems -- as a variable through the Inspector.

    • @allndall7126
      @allndall7126 Před rokem

      Use layer

  • @andreygubin2047
    @andreygubin2047 Před rokem

    Thanks a lot, what was very helpful.

  • @dattran1630
    @dattran1630 Před 5 měsíci

    error CS1061: 'ParticleSystem' does not contain a definition for 'play' and no accessible extension method 'play' accepting a first argument of type 'ParticleSystem' could be found (are you missing a using directive or an assembly reference?)
    This is the problem I have, please tell me what the error is and how to fix it , THANK U

    • @Savallion
      @Savallion  Před 5 měsíci

      If you are ever having a problem with one of Unity's components / packages / libraries / etc. you should refer to the documentation for it to find the problem. Here is the ParticleSystem documentation:
      docs.unity3d.com/ScriptReference/ParticleSystem.html
      From the brief error message you've posted here, I would guess the problem is using a lowercase "play" instead of "Play" but in the end I cannot debug your code for you, you will have to learn how to do it :)

  • @Bond007in
    @Bond007in Před 11 měsíci

    10:30 start

  • @RexSmithII
    @RexSmithII Před rokem

    What is the easiest way if I’m bringing in animation to a model that the dialogue is already sync up? Is there a easy way for just adding a sound to the animation without events?

    • @Savallion
      @Savallion  Před rokem

      I think your instinct is right - I wouldn't use animation events for this.
      I personally haven't done dialogue synced with animations (yet), but I think I would probably just have the animation on a Trigger in the Animator. Then, I would have some code that sets the animator Trigger & plays the dialogue sound at the same time. Since you'll likely need some kind of system to show the dialogue on screen anyway, there should be central place where you can fire off these events all together (and by this I mean regular events, not animation events). This would also allow you to trigger different animations based on the dialogue. Whatever system you're using to load the dialogue text & sound could also have an animation trigger name attached to it.
      I hope that helps!

  • @fl641
    @fl641 Před rokem +1

    Cant get the EVENTS in the inspector. I do not know why, I do not know what I am missing. It sais "NO ANIMATION DATA AVAILABLE IN THIS MODEL".. but i have several animations working fine in the game. Can someone help me?

    • @fl641
      @fl641 Před rokem

      I have imported all my models from blender to unity, but I created the animations in Unity. So all animations are working on my game but i just happen not to have the "events" in animations in the inspector of the model.. Any idea about how to fix this?

    • @Savallion
      @Savallion  Před rokem +1

      You mentioned that you used Unity to make the animations, not Blender -- this means that you won't have animation data in the model.
      To add animation events to your Unity animations you will need to open that animation in the Animation window (not to be confused with the Animator window, they have very similar names).
      From there, you won't have a separate section that says "events" but you can see just below the seeking controls there is a small button with the same little arrow flag icon that you can use to add animation events to Unity animations. This page on Unity's documentation should show you exactly where it is:
      docs.unity3d.com/Manual/script-AnimationWindowEvent.html

    • @fl641
      @fl641 Před rokem +1

      @@Savallion thank you so much for your help! I really appreciate. And thank you so much for this great video :)

  • @Inferim
    @Inferim Před rokem

    Neat!

  • @ferasalfarsi897
    @ferasalfarsi897 Před 8 měsíci

    Please, zoom in. the script is very small. It is hard to see and read.

    • @Savallion
      @Savallion  Před 8 měsíci +1

      Apologies! I do try to increase text size on code for videos, but I must have forgotten on this one. If it helps, the code is quite simple. First, within the component I have two public variables for the left foot ParticleSystem and the right foot ParticleSystem (these are assigned in the inspector). Within a void function called FootStepEvent which takes in an integer "whichFoot", we have an if statement. If whichFoot is 0, we call .Play() on the left foot particle system, and else we call .Play() on the right foot particle system.
      That's all it's doing!

    • @ferasalfarsi897
      @ferasalfarsi897 Před 8 měsíci

      Thank you so much for you assist @@Savallion
      It works!!

  • @MikeGlaxo
    @MikeGlaxo Před rokem

    Nice one, top clarity. Please add more energy. Thx and bye

  • @DaveSucker
    @DaveSucker Před měsícem

    hmm now that was helpful