|
Post by capitalj on May 2, 2014 3:15:13 GMT
Hi,
I've just started working with Master Audio and have a question and pooled prefab objects. I notice that there is built in support for a few pooling systems but what is the best approach if an unsupported pooling system is used along with the EventSounds script?
For example, I have particle effects that are pooled using CFX SpawnSystem (as well as my own custom pooling system). These effect objects have an Event Sounds script on them. If I set the event to trigger on Start then it will only play once. If I set it to trigger on Enable then it will play as soon as the scene is loaded. The Unity Audio Source component works perfectly with this setup if you set Play on Awake to on.
Thanks! -JJ
|
|
|
Post by DarkTonic Dev on May 2, 2014 4:29:32 GMT
The Unity Audio Source will not play the AudioClip when a pooled object respawns, only the first time.
But correct, Awake and Start events should not be used with pooled objects because that only happens the first time the objects is spawned, not with respawns. After that, it's just the object disabling and enabling itself. So, if you use Pool Manager or our pooling in Core GameKit (Pool Boss), you can use the Spawned event to trigger sounds or other Master Audio actions. Otherwise, there's no official support for other systems.
However, Enable may work, as long as you set the object to disabled when it's not emitting. If that doesn't work, I suggest you modify your custom pooling system to broadcast messages so that it will function just like Pool Manager. Add the following line of code right after you spawn an object assigned to the variable "pooledObject":
pooledObject.BroadcastMessage("OnSpawned", SendMessageOptions.DontRequireReceiver);
And also add the following line right before you despawn an object.
pooledObject.BroadcastMessage("OnDespawned", SendMessageOptions.DontRequireReceiver);
And then you should be able to use the Spawned and Despawned events in EventSounds.cs
|
|
|
Post by capitalj on May 2, 2014 20:16:47 GMT
Ok I'll try modifying my pool manager to broadcast that message. Thanks!
|
|
|
Post by DarkTonic Dev on May 2, 2014 23:20:28 GMT
You're welcome!
|
|