UE4 heavily use assertion. Assertion fail happens if mentioned condition fails, this condition is what code susspect to be true for stable operation, anything else is expected to cause a crash, so insted of letting that happen it crashes it self with info which condition failed. You can read about assertion here
So by that it sould be very clear what failed, IsInAudioThread()
means that this function was expected to only run on audio thread and you calling it from game thread. I also check the code and theres no check for development build, this check happens out of the bat always on that function, so cause might be something else (like you calling this function only in development build or function you make a call is executed by audio thread on other builds then devlopment build, or something else).
You can access audio thread controls from this class:
What will interest you the most is RunCommandOnAudioThread(TFunction<void()>)
which let you execute function in audio thread, it is best to use lamdas (nested functions) to pass this
pointer:
FAudioThread::RunCommandOnAudioThread([this]()
{
//code that will run in audio thread
});
You can pass more variables in by adding it like this [this,VarA,VarB]
Now here the catch, if you know a little big about threading you should know this function won’t be executed with sequance of game thread, it will be executed later on (next time when audio thread will be free), so you wont be able to get return of a function, because when it’s gonna run you game thread function is most likely already be finished. So best practice is to do actual actions then getting values. here nice exmaple from FAudioDevice (this function was made to run on both game and audio thread and you can see code is breaching off depending on which thread it runs):
void FAudioDevice::StopActiveSound(const uint64 AudioComponentID)
{
if (!IsInAudioThread())
{
DECLARE_CYCLE_STAT(TEXT("FAudioThreadTask.StopActiveSound"), STAT_AudioStopActiveSound, STATGROUP_AudioThreadCommands);
FAudioDevice* AudioDevice = this;
FAudioThread::RunCommandOnAudioThread([AudioDevice, AudioComponentID]()
{
AudioDevice->StopActiveSound(AudioComponentID);
}, GET_STATID(STAT_AudioStopActiveSound));
return;
}
FActiveSound* ActiveSound = FindActiveSound(AudioComponentID);
if (ActiveSound)
{
AddSoundToStop(ActiveSound);
}
}
If you can’t, you will need to do call back to game thread with RunCommandOnGameThread
to send results back