# How save to wav in unity with non real time?

**URL:** <https://qa.fmod.com/t/how-save-to-wav-in-unity-with-non-real-time/15904>\
**Category:** Unity\
**Created:** [June 20, 2020, 7:23am UTC](https://qa.fmod.com/t/how-save-to-wav-in-unity-with-non-real-time/15904 "2020-06-20T07:23:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SilentAndroid](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@SilentAndroid](https://qa.fmod.com/u/SilentAndroid)\
**Post date:** [June 20, 2020, 7:23am UTC](https://qa.fmod.com/t/how-save-to-wav-in-unity-with-non-real-time/15904/1 "2020-06-20T07:23:42Z")

</div>

Hi! I try to save wav file with fmod from unity.

My code:

FMOD.Studio.EventInstance myInstance;

public void Save()  
{

FMODUnity.RuntimeManager.CoreSystem.setOutput(FMOD.OUTPUTTYPE.WAVWRITER\_NRT);  
FMODUnity.RuntimeManager.CoreSystem.init(128, FMOD.INITFLAGS.STREAM\_FROM\_UPDATE, IntPtr.Zero);

myInstance = FMODUnity.RuntimeManager.CreateInstance(“event:/myevent 4”);  
myInstance.start();

var state = FMOD.Studio.PLAYBACK\_STATE.STARTING;

while(state != FMOD.Studio.PLAYBACK\_STATE.STOPPED)  
{  
FMODUnity.RuntimeManager.CoreSystem.update();  
myInstance.getPlaybackState(out state);  
}

myInstance.stop(FMOD.Studio.STOP\_MODE.IMMEDIATE);  
FMODUnity.RuntimeManager.CoreSystem.setOutput(FMOD.OUTPUTTYPE.AUTODETECT);  
FMODUnity.RuntimeManager.CoreSystem.init(128, FMOD.INITFLAGS.NORMAL, IntPtr.Zero);  
}

This code get stuck in while-loop. And saves in wav many many nulls. Wav file contains only silence.

What am I doing wrong?

My code 2:

FMOD.Studio.EventInstance myInstance;

public void Save()  
{

FMODUnity.RuntimeManager.CoreSystem.setOutput(FMOD.OUTPUTTYPE.WAVWRITER); // REAL TIME  
FMODUnity.RuntimeManager.CoreSystem.init(128, FMOD.INITFLAGS.NORMAL, IntPtr.Zero); // normal flag

myInstance = FMODUnity.RuntimeManager.CreateInstance(“event:/myevent 4”);  
myInstance.start();

}

This code work. And saves event data to wav at real time.

But I need NRT code.

Please, help. 🙂

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [June 29, 2020, 5:37am UTC](https://qa.fmod.com/t/how-save-to-wav-in-unity-with-non-real-time/15904/2 "2020-06-29T05:37:52Z")

</div>

First thing would be to check if all the FMOD functions are returning any errors, they should all return an `FMOD.RESULT`.

You are probably better off creating and using your own FMOD System references, the ones in the RuntimeManager are being created and initialized with all the settings from the editor.
