Reloading audio with animation events

WillyG99

Member
Hi, i'm a bit lost on the audio part for reloading, i need different sounds for a reloading animation, sounds for the following:
Unloading clip
Loading in clip
Cocking the weapon

So 3 or more sounds for reloading, how would i set the animator to play those sounds by using animation events?

I read the documents on Animator Audio States, but i'm still a bit lost on how it works, not sure how to pull this off.
 
Another issue with layers and rendering, can't find the issue. Some settings or layers are incorrect making the skybox/fog/clouds pass through everything, placed a zombie there for showcase. .png
 
There is only one reload Audio State Set for this you have a couple of options:

1. Subclass shootable weapon and add your own reloading animation events.
2. Combine all of the audio clips into a single one and play that clip.

Another issue with layers and rendering, can't find the issue. Some settings or layers are incorrect making the skybox/fog/clouds pass through everything, placed a zombie there for showcase.
I am not sure on this one but the first person objects are rendered with the First Person Camera so maybe you need to adjust your settings there as well?
 
There is only one reload Audio State Set for this you have a couple of options:

1. Subclass shootable weapon and add your own reloading animation events.
2. Combine all of the audio clips into a single one and play that clip.


I am not sure on this one but the first person objects are rendered with the First Person Camera so maybe you need to adjust your settings there as well?
Ok thank you, will try the reloading soon!

The rendering is still messed up though, i'm using the newest version of unity, which is 2022.1.0a13. Might be something there messing with the sky and fog rendering and the ufps layers. The only "fix" i found was making the fps camera also render "default" which removes the whole point of having an fps camera, but it's the only fix i've found so far sadly. I've been messing the fog and cloud renderer and all the layers but i can't figure it out, so i'll do it like this for now.
 

Attachments

  • 1.png
    1.png
    938.2 KB · Views: 5
Hm can't say I've seen that camera rendering issue before... looks like you're using a very recent version of Unity, I'd check on their forums to see if anyone else has had this issue as well. There may be some camera rendering order type thing that needs to be set.
 
For anyone curious on the reload events, i'll show how you can play audio on animation events, it's really easy actually.

Make a code with the sounds you want, i'll post my really basic code as an example.
Attach this code to your weapon that has the animator and audiosource:

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [RequireComponent(typeof(AudioSource))]
  5. public class ReloadSounds : MonoBehaviour
  6. {
  7. AudioSource audioSource;
  8. public AudioClip MagGrab;
  9. public AudioClip MagOut;
  10. public AudioClip MagIn;
  11. public AudioClip PocketMag;
  12. void Start()
  13. {
  14. audioSource = GetComponent<AudioSource>();
  15. }
  16. void MagGrabEvent()
  17. {
  18. audioSource.PlayOneShot(MagGrab);
  19. }
  20. void MagOutEvent()
  21. {
  22. audioSource.PlayOneShot(MagOut);
  23. }
  24. void MagInEvent()
  25. {
  26. audioSource.PlayOneShot(MagIn);
  27. }
  28. void PocketMagEvent()
  29. {
  30. audioSource.PlayOneShot(PocketMag);
  31. }
  32. }

As you can see i have made events, they will be triggered by your animation events, i'll show an example of how i set up mine with a picture.

Hope this helps somebody :)
 

Attachments

  • Screenshot_2.png
    Screenshot_2.png
    86.6 KB · Views: 5
Top