Audiokinetic's Community Q&A is the forum where users can ask and answer questions within the Wwise and Strata communities. If you would like to get an answer from Audiokinetic's Technical support team, make sure you use the Support Tickets page.

With Unity, what's recommended if I want to PostEvent a Sound from an object that is then deleted?

+2 votes

[Relating to WWISE in Unity]

Let's say you want to trigger a sound effect when a Unity gameobject is destroyed (e.g. item explodes or is collected).

As I understand it when you call AkSoundEngine.PostEvent, "At runtime, an AkGameObj component is automatically added to this GameObject", but if I Destroy the Unity GameObject after posting the event, I get the error:

Wwise: Unknown game object ID. Make sure the game object is registered before using it and do not use it once it was unregistered.(Object: [myobjectname] (UnityEngine.GameObject))

 

Seems like a very common scenario - is there a recommended way to handle this case?

 

asked Jun 24, 2015 in General Discussion by Chris (690 points)
I've tried a couple workarounds for this too,  these also seemed to give a console warning:

--- #1 - Create a new object just to play the sound whilst deleting the originating object ---
I created a new component for these OneShot sounds: I then play a sound via that component (and delete the originating game object) - I did this via a PostEvent with a callback that was called when the Event ended. In that callback, I delete the OneShot object.

--- #2 - Unregister before deleting the object ---
I post the event and then immediately unregister the game object with the sound engine.
Quick update: I hear that this is resolved in the very soon to be released WWISE 2014.1.6 and 2015.1

1 Answer

0 votes
 
Best answer
For me, this appears to be fixed in the recently released WWISE 2015.1 - seem to be able to Destroy() objects without generating any warnings
answered Jul 24, 2015 by Chris (690 points)
...