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.

0 votes

I have a sound playing once, when some action occurred, and while the sound is playing, I lock the listener for the action, and on EndOfEvent I unlock the listener, so that the sound can be activated again.

Now the problem is, that it works for a while, and then it stops working, where it is specifically the EndOfEvent that fails after the sound has started playing (knowledge gained through prints).

So what I want to know is why the EndOfEvent could fail to activate.

I am new to wwise, so I'm sorry if it is a stupid mistake I made in the syntax or if this has already been resolved somewhere else, but I cannot seem to find anything that relates to this hickup,

 

I work in Unity with C#, and this is the relevant code:

 

void FixedUpdate () {

        if(!audioFired){

                if(runCounter == maxRuns){

                        CalculateSpeed();

                        runCounter = 0;

                }

                runCounter++;

        }

}

 

void CalculateSpeed(){

        (...some caluclations to find inputValue...)

        if(inputValue >= minActivationSpeed){

                AkSoundEngine.PostEvent(WwiseReferenceName, gameObject, (uint) AkCallbackType.AK_EndOfEvent, HandleCallBack, thecookie);                 //thecookie is a public class holding information about what gameObject we are refering to, and what name it has

        }

}

 

void HandleCallBack(object m_cookie, AkCallbackType m_type, object someObject){

        audioFired = true;

        if(m_type == AkCallbackType.AK_EndOfEvent){

                audioFired = false;

                runCounter = 0;

        }

}

 

Best regards

LR

in General Discussion by Lisbeth R. (250 points)
Hi Lisbeth,

Did you figured out how to solve this problem and make it work? I'm having exactly the same problem with EndOfEvent, sometimes it work and sometimes it doesn't.

Cheers.
As I recall it, we did not find out why it did so. Also I have not looked at that for more than a month now. However, I have some theories about it.

One is that the 'package' from wwise gets lost on the way, while another concerns with the soundmixer (or what it was we were using at that point) entered a form of 'sleep' mode.

A thing I can suggest instead of the end of event is 'custom cues', 'exit' and 'enter'. Those seems to be really reliable in this way. But I will check in with the wwise guy tomorrow, because of a conversation I had with him today about the different systems in wwise. I'll be back with an update tomorrow.

If you need the coding examples of how to get the custom cue, enter or exit, let me know :)
After struggling with this and testing it over and over, at one point  I got this message on the console:

WwiseUnity: EventCallbackPackage not found for <-907605440>.
UnityEngine.Debug:LogError(Object)
AkCallbackManager:PostCallbacks() (at Assets/Wwise/Deployment/API/Handwritten/AkCallbackManager.cs:354)
AkSoundEngineController:LateUpdate() (at Assets/Wwise/Deployment/Components/AkSoundEngineController.cs:79)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

I am not really a programmer at all so I don't really know what it means, but looking for this error I end up here:

https://www.audiokinetic.com/library/edge/?source=Unity&id=unity__wwise__types.html

In case you still want to solve this and give it a try, I changed my code with the one on the second example on the link and now it works perfectly.

Although the callbacks are working for me now, I am indeed interested in the custom cues if you can share that code :)
The error seems to be that the 'package' sent form wwise to unity either got lost, or did not exist in the first place (e.g. you posted an event and made a typo in the name of the event). As it is converted the the integer "907605440", I cannot get specific on any other thoughts related to the error.

I am happy that you solved it, I will deff try it out as soon as possible :)

In regards to the custom cues, this is the relevant code (C#)



(imported libraries)

public class SomeAwesomeNameHere(){

    public class TheCookie{
        public string theWWiseName = "";
        public GameObject thisGameObject = null;

        public TheCookie(string theWwiseName, GameObject thisGameobject){
            this.theWWiseName = theWwiseName;
            this.thisGameObject = thisGameobject;
        }
    }

    public TheCookie thecookie;

    void Start () {
        (...some pretty code here...)
    }

    void Update(){
        (...more pretty code...)
        if(some condition to fire my function){
            startingMyPostEvent()
        }
    }

    void startingMyPostEvent(){
        AkSoundEngine.PostEvent( "pretty wwisename", theGameObjectToPlayFrom
            (uint) AkCallbackType.AK_MusicPlayStarted |   
            (uint) AkCallbackType.AK_MusicSyncEntry |
            (uint) AkCallbackType.AK_MusicSyncBar |
            (uint) AkCallbackType.AK_MusicSyncBeat |
            (uint) AkCallbackType.AK_MusicSyncExit |
            (uint) AkCallbackType.AK_MusicSyncUserCue| //what you want
            (uint) AkCallbackType.AK_EndOfEvent,
            HandleStateChanges, thecookie);
    }

    void HandleStateChanges(object m_cookie, AkCallbackType m_type, AkCallbackInfo m_info){

        (...irrelevant code omitted...)

        if( m_type == AkCallbackType.AK_MusicSyncUserCue ) {
            Debug.Log(((AkMusicSyncCallbackInfo) m_info).userCueName);
            
    }
    }
}



Also, just passing on some knowledge I learned, any messages to and from wwise, will first take effect at the end of a frame.

Or in other words, at the beginning of a frame all code is read through by the program, and all that relates to wwise is stored to only be sent/executed in the end of the frame.

This means that if you in the above HandleStateChanges() for instance call another normal void funciton, that function would run first before any of the other code in the HandleStateChanges() is executed.

1 Answer

0 votes
 
Best answer

I encountered the same problem and I think I've figured it out.

REASON: Reused Cookies.

The destructor of EventCallbackPackage calls AkCallbackManager.RemoveEventCallbackCookie, which literally removes all registered callbacks with the same cookie.
The EventCallbackPackage won't be finalized until GC happens. That should explain why callbacks will work for a while but fail then after.

Passing a new cookie every time fixed the problem for me.

by Jue H. (440 points)
selected by Lisbeth R.
Due to a change in the system setup we are no longer using a continous listen for end of event. But if we are going to use it again, I will be sure to test out this method.

It seems to be very possible however, and I am going to mark your answer as the solution.

Thank you very much for it :)
...