playMaker

Author Topic: [Solved] Play Random Sound issue  (Read 2147 times)

wirejaw

  • Playmaker Newbie
  • *
  • Posts: 49
[Solved] Play Random Sound issue
« on: May 01, 2022, 12:56:38 PM »
I'm using Play Random Sound to play footstep Audio Clips on my player character and I cannot figure out how to make the sounds louder.  My game is a 2.5D side scroller and I have the Position for the clips on my Player Character Object, and have my Camera set as the Listener.  The sounds play but they are barely audible, assuming because they are too far away from the Camera. I have the Volume in my Play Random Sound set to 1, and I don't see any additional volume settings in the source Audio Clips.  I was wondering if I need to make an Audio Source for each clip, but I don't see how to add Audio Source objects to the Play Random Sound action.

I've tested having the sounds Position on the Camera itself and the volume is fine in this case but the the 3D spatial position is lost and it just sounds wrong.  My Camera is dynamic (using Pro Camera 2D), using Forward Focus, zooming triggers, etc., so my Player Character can be in a variety of positions in relation to it and I really want my Character-generated sounds to come directly from the Player Character's position.  Footsteps are the first of many sounds I will be adding the the Player and I need to get this resolved before adding more sounds.

Thanks much for any help.
« Last Edit: May 03, 2022, 08:28:19 PM by wirejaw »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Play Random Sound issue
« Reply #1 on: May 02, 2022, 02:46:20 PM »
Hi.
Play random sound is actually creating and destroying an audio source.
so for foot steps, this is a bad way to do this.

what you can do is, make an array with you audio clips, then use Array Get Random and store the clip.
Then use Audio Play, now it will use the Audio source.

if the volume is set to 1 and its still not loud enough, its best to increase the volume on the clip file it self.
You can use for example Audacity (free)

On the Audio Source, on the Output you can connect a audio mixer. (look up Audio Mixer Unity on google or youtube)

wirejaw

  • Playmaker Newbie
  • *
  • Posts: 49
Re: Play Random Sound issue
« Reply #2 on: May 02, 2022, 04:01:08 PM »
Great thanks for the help djaydino I will try that.

wirejaw

  • Playmaker Newbie
  • *
  • Posts: 49
Re: Play Random Sound issue
« Reply #3 on: May 02, 2022, 11:30:20 PM »
Djaydino I've been trying to work this out but still having issues.  Please understand  I am very new to Arrays and new to audio in Unity.

Currently I think I have a setup that is close, but I can't hear any of the footstep sounds.  I made a global array variable and added all of the footstep clips as shown in the attached screenshot.  Do I need to have an audio source component attached to each separate clip?  The only way I was able to successfully add the clips to the array list was by dragging them into the Hierarchy, at which point audio source components were added to each one automatically.  Is this the right way to do this?  I also then made each clip into a prefab, but also not sure if that is necessary either.

On my Player character prefab I have raycasts shooting down from each heel joint, triggering RightFootDown, LeftfootDown, where I have my Array Get Random which chooses the AudioFootstepsArray global variable and stores the value as "Footstep" like you suggested.  Then the Audio Play plays Footstep.

I can see the Array Get Random selecting random clips from the list, and the Audio Play is populated with the random clip (Footstep), but I'm not hearing any sound.  I've double checked the clips and they should be barely audible when playing from the player's position. 

No idea if I'm doing this correctly so any guidance is much appreciated.  Thanks again for your help!





djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Play Random Sound issue
« Reply #4 on: May 03, 2022, 10:18:06 AM »
Hi.
Your array should hold the AudioClips, not gameobjects.

then on the Audio Play, after you got a random audioclip
Set the variable on the "One Shot Clip"

Have a Audio source component on the player and target the object (on the Audio Play action 'GameObject' , if the fsm is on the same object, leave it to Use Owner.

if the player is always centered you can set the Audio Source to 2D

wirejaw

  • Playmaker Newbie
  • *
  • Posts: 49
Re: Play Random Sound issue
« Reply #5 on: May 03, 2022, 11:25:49 AM »
I assumed I may need Array Maker from the Ecosystem for this, so I imported it into my project.  After importing I didn't see Array Maker in the Playmaker Addons list, so I closed unity and re opened my project, at which point Playmaker no longer showed up on my menu, and I could no longer run my game and there were several errors related to Array Maker.  I deleted Array Maker from my Project list but I am still unable to run my game, seeing the errors currently on the attached screen shot.

Any help is appreciated!

wirejaw

  • Playmaker Newbie
  • *
  • Posts: 49
Re: Play Random Sound issue
« Reply #6 on: May 03, 2022, 11:49:21 AM »
I was able to get my game running again by removing some of the array actions that I think were the cause of my issues. 

Do I need the Array Maker add on for what I am trying to do?  If so, any idea why when I imported it didn't show up and caused these issues?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Play Random Sound issue
« Reply #7 on: May 03, 2022, 03:44:44 PM »
Hi.
You can use the normal build in array's

For audio files, select Array Type "Object"
the select Object Type "UnityEngine/AudioClip"

wirejaw

  • Playmaker Newbie
  • *
  • Posts: 49
Re: [Solved] Play Random Sound issue
« Reply #8 on: May 03, 2022, 08:29:04 PM »
I've got it working now as intended.  Thanks much!