Community Q&A

Where Wwise users help each other out!

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

Is it possible to pass an Action as a callback when using AkEngine.PostEvent in the Unity integration?

+1 vote
I'm trying to have a callback fire when an event is complete; I can get this to work by passing the Callback() method (seen below) in to PostEvent, but I'd like to be able to pass other delegates in, like the action in the method signature below:

    public override void PlaySound(uint event, GameObject sender, System.Action<object, AkCallbackType, object> callback = null)
        AkSoundEngine.PostEvent(event, sender, (uint)AkCallbackType.AK_EndOfEvent, callback, null);

    private void Callback(object in_cookie, AkCallbackType in_type, object in_callbackInfo)
    {     }

I sort of expected this to work, but I'm getting an error ("cannot convert `System.Action<object,AkCallbackType,object>' expression to type `AkCallbackManager.EventCallback'"). Is this possible? I was unable to find a similar example in the Unity integration demo project, the documentation included in that demo project, or online.


edit: Ah, found a solution; you can pass an action in to the constructor for an EventCallback:

AkCallbackManager.EventCallback ec = new AkCallbackManager.EventCallback(new System.Action<object, AkCallbackType, object>((o1,o2,o3) => Debug.Log("Callback")));

AkSoundEngine.PostEvent(eventId, sender, (uint)AkCallbackType.AK_EndOfEvent, ec, null);
asked Jan 18, 2017 in General Discussion by Christopher M. (110 points)
Thanks a lot!

Please sign-in or register to answer this question.