- Home /
Solved
UnityWebRequest hangs on isDone but not always
Hi guys Having a weird problem here hope someone might be able to help I have two buttons calling the same function, this function creates a web request to get a wav file from a specific path, this path is the same for both buttons , however one just gets the sample and plays it in an audio source and the other is suppose to get the sample load it to another audio source but not play it, the weird this is with the second button isDone never turns true and downloadProgress never goes above zero, therefore the function never reaches the next step where i test which button was pressed.
Really hope someone can help Regards!
public string path;
AudioSource aSource1;
AudioSource aSource2;
public IEnumerator SomeFunction ( bool isPreview ){
AudioClip wavFile;
UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(path, AudioType.WAV);
www.SendWebRequest();
while (!www.isDone)
{
yield return www.isDone;
}
// Button 2 never reaches this point
if (www.isNetworkError)
{
Debug.Log(www.error);
}
else
{
wavFile = ((DownloadHandlerAudioClip)www.downloadHandler).audioClip;
if ( buttonNumber == 0)
{
aSource1.clip = wavFile;
aSource1.Play;
}
else
{
aSource2.clip = wavFile;
}
}
}
Answer by farhanblu · Jan 04, 2020 at 11:10 PM
How can you yield from a void method? The script with this function (which should return an IEnumerator) should not compile.
Secondly, again I am not sure if you can yield return a boolean. It should be a yield instruction or null
yield return null;
should do it. Not commenting on the rest of the code.
you're right there, but that wasn't the problem because in the original code it is IEnumerator not void, just a typo here, i did find what the problem was though, i was disabling the game object before the code finished executing, thanks anyway!
Follow this Question
Related Questions
Delayed Button Sounds 0 Answers
Multiple Cars not working 1 Answer
WWW.audioClip not playing on android build 1 Answer
Buttons sounds are only playing once, then the sound no longer plays? 0 Answers
Speed of WWW 1 Answer