magique
Full Member
Posts: 194
Posts: 194
|
Post by magique on Mar 12, 2016 17:32:48 GMT
I just started using Master Audio for the first time and I notice something undesirable. I have a component that creates a pool of bullets for my player ship to fire. Each of these bullets has a Master Audio Event Sounds script attached with an Enable trigger. The problem is that as soon as the object gets instantiated, it plays the sound. Is there any way to get around this issue? Doing it the old way, I would set the Play on Awake to false so this doesn't happen, but I don't yet see an equivalent functionality here.
|
|
|
Post by DarkTonic Dev on Mar 12, 2016 19:31:15 GMT
That's when the enabled event first fires if you look at the Unity event life cycle, so that's correct behavior. Maybe you want to use the Visible event? Play on awake in all Audio Sources used by Master Audio is set to false.
Normally we use the OnSpawned event since we use pooling (Core GameKit and PoolManager both use this event).
|
|
magique
Full Member
Posts: 194
Posts: 194
|
Post by magique on Mar 12, 2016 20:16:42 GMT
That's when the enabled event first fires if you look at the Unity event life cycle, so that's correct behavior. Maybe you want to use the Visible event? Play on awake in all Audio Sources used by Master Audio is set to false. Normally we use the OnSpawned event since we use pooling (Core GameKit and PoolManager both use this event). OnVisible won't work for me. I've switched to using the static function PlaySound3DAtVector3AndForget(). Since I was already calling a sound play function in my scripts, it was easy to just replace with this call instead. So, are you saying that sounds in MasterAudio aren't pooled? Does it then instantiate an AudioSource every time I ask it to play a sound?
|
|
|
Post by DarkTonic Dev on Mar 12, 2016 21:31:11 GMT
That's when the enabled event first fires if you look at the Unity event life cycle, so that's correct behavior. Maybe you want to use the Visible event? Play on awake in all Audio Sources used by Master Audio is set to false. Normally we use the OnSpawned event since we use pooling (Core GameKit and PoolManager both use this event). OnVisible won't work for me. I've switched to using the static function PlaySound3DAtVector3AndForget(). Since I was already calling a sound play function in my scripts, it was easy to just replace with this call instead. So, are you saying that sounds in MasterAudio aren't pooled? Does it then instantiate an AudioSource every time I ask it to play a sound? Pooled, no. But it has something in common with pooling in that there are zero Instantiate / Destroy calls ever. Everything with an Audio Source that is located under the Master Audio game object is created when the Scene starts so it's always available for use during play. If you need there to be 6 bullet sounds able to play at the same thing, there are 6 game objects for this ready and waiting (you specify how many of each to create and the default is 1). I still don't understand why EventSounds doesn't work for you. Normally you would want to play a sound when a bullet appears / is spawned / instantiated, etc. Which that script can do a number of ways. So what is it that makes it not suitable? Or are you just not using it right?
|
|
magique
Full Member
Posts: 194
Posts: 194
|
Post by magique on Mar 12, 2016 22:32:03 GMT
I still don't understand why EventSounds doesn't work for you. Normally you would want to play a sound when a bullet appears / is spawned / instantiated, etc. Which that script can do a number of ways. So what is it that makes it not suitable? Or are you just not using it right? I built my game around creating pooled objects and those pooled objects are set to inactive when not in use. When I want to use one, such as a bullet, I simply position it where I want and then activate it. Activating it doesn't fire an OnBecameVisible. So, the OnEnable worked for me, but had the side effect of playing the sound when it was instantiated in my Awake function. Maybe there is another way to make it work, but I'm not sure. I only started playing with this this morning.
|
|
|
Post by DarkTonic Dev on Mar 12, 2016 23:32:26 GMT
When you first Instantiate it, you should instantly make it disabled, and it should work properly. That's exactly how pooling works.
|
|
magique
Full Member
Posts: 194
Posts: 194
|
Post by magique on Mar 13, 2016 0:15:18 GMT
When you first Instantiate it, you should instantly make it disabled, and it should work properly. That's exactly how pooling works. I instantly do a SetActive(false), but maybe you mean enabled = false?
|
|
|
Post by DarkTonic Dev on Mar 13, 2016 0:45:56 GMT
No, that should work. Weird.
Then, if you add an OnSpawned method to your class that you call when it gets spawned (not during awake / start), you can use the "spawned" event. That will definitely work.
|
|
magique
Full Member
Posts: 194
Posts: 194
|
Post by magique on Mar 13, 2016 3:28:52 GMT
No, that should work. Weird. Then, if you add an OnSpawned method to your class that you call when it gets spawned (not during awake / start), you can use the "spawned" event. That will definitely work. I'm not sure I understand this technique. I'm supposed to add a method called OnSpawned and then I directly call this method myself when my object is activated? And if I use the Spawn event then it will somehow key off of this?
|
|
magique
Full Member
Posts: 194
Posts: 194
|
Post by magique on Mar 13, 2016 3:52:37 GMT
Nevermind. I am using this in another project and the Enable event is working as it should be. I'm not sure why it didn't work before. One more thing for now. You said earlier the following:
"If you need there to be 6 bullet sounds able to play at the same thing, there are 6 game objects for this ready and waiting (you specify how many of each to create and the default is 1)."
Where do you set this value? I'm looking everywhere and I don't see where to set this.
EDIT: I found it. The name threw me off.
|
|
|
Post by DarkTonic Dev on Mar 13, 2016 7:36:00 GMT
"If you need there to be 6 bullet sounds able to play at the same thing, there are 6 game objects for this ready and waiting (you specify how many of each to create and the default is 1)." Where do you set this value? I'm looking everywhere and I don't see where to set this. EDIT: I found it. The name threw me off. People get confused about this feature, usually a couple people every month. Is there a better name you could suggest that would make it clearer.?
|
|
magique
Full Member
Posts: 194
Posts: 194
|
Post by magique on Mar 13, 2016 14:56:36 GMT
My confusion mainly stems from the fact that I am not that knowledgeable about the Unity audio system. I didn't even know that Unity called them Voices until I started using Master Audio. If I had known that then it probably wouldn't have been as confusing. The word Weighted in parenthesis also adds to the confusion. But this is probably not an issue for a sound guy.
|
|
|
Post by DarkTonic Dev on Mar 13, 2016 21:11:33 GMT
Yeah well it is dual purpose. It also functions as weight for randomness, so it would be silly to not show that in the label.
No one has a better suggestion for the naming yet, so I guess it will stay as is.
|
|