Channel Error with PlayOneShot Using Instantiate and WWW Bug

Example:

WWW www = new WWW("file://" + userFilesPath + "HHT_Demolish1.wav");
yield return www; //wait for file to finish loading

AudioClip clip = www.GetAudioClip(false);
managerObj.audio.PlayOneShot(clip);

AudioClip clip2 = (AudioClip)Instantiate(clip);
managerObj.audio.PlayOneShot(clip2);

managerObj.audio.clip = clip2;
managerObj.audio.Play();

The first PlayOneShot works. The second PlayOneShot returns error “oneshot->channel”. The last Play works.

So it seems that if you instantiate an AudioClip generated from WWW, you will get a channel error if calling PlayOneShot with it. Also wanted to point out that if I use Resources.Load, PlayOneShot is able to play multiple copies of the same sound, where as if I pass it an AudioClip from WWW, it will only play one copy of the sound (i.e. subsequent plays of the same clip with new sources will restart the clip rather than play a new instance).

I’m seeing something similar after upgrading to Unity 3.4. Basically, when playing any sound effect via WWW when the sound is already being played once (so that two copies of the same effect overlap one another), it crashes with this error. AND the error can’t be caught via a try/catch block, which is the most odd bit.

This is code that worked fine from Unity 2.6 through 3.3, and which is in three of my games in the hands of 80k+ customers. Now with Unity 3.4, however, my working build crashes within a few seconds of being run.

Oh, one question – did you already submit this as a bug report, or shall I?

I have not. Have to look up how so you go for it :wink:

Though it seems we are having slightly different errors.

Np, I just submitted it. For future reference, it’s under Help, Report Bug, in Unity itself. :slight_smile:

Oh, and yes – we are having slightly different error results, but I think that the root cause is probably very similar. Something isn’t happening correctly when WWW audio clips are loaded and played using playoneshot, and so in your case that makes them non-duplicatable via instantiate, and in my case it makes it so that multiple WWWs can’t be established to the same file and used in PlayOneShot multiple times.

using Instantiate on clips generated from the WWW class returns a clone that has a length of 0. This would indicate that in 3.4 the clips are not being cloned correctly.

Okay, cool extra details. I passed that along on the bug report.

Just want to confirm this bug.

public AudioClip stoneVanishSound;

IEnumerator Start()
{
string url;
WWW w;
                
url = "file://"  Application.dataPath  "/../sounds/stone_vanish.ogg";
w = new WWW(url);
yield return w;
stoneVanishSound = w.GetAudioClip(false);

audio.PlayOneShot(stoneVanishSound, 0.70f);
audio.PlayOneShot(stoneVanishSound, 0.70f);
audio.PlayOneShot(stoneVanishSound, 0.70f);
}

Problem: Sound is played just 1 time.
I’m getting 2 errors:

“oneshot->channel
UnityEngine.AudioSource:PlayOneShot(AudioClip, Single)”

If I assign this sound from editor and run the application, error does not appear and sound is played 3 times.

PS: Also submitted a bug report.

Awesome thank you! Hopefully if they get more reports of this, they will give it a higher priority.

Same problem here, incredibly annoying since it’s supposed to be one of the core features in my project.

Hi did you tried :

private var source : AudioSource;

function Start () 
{
  source = gameObject.AddComponent (AudioSource);

  www = new WWW (url);
  yield www;
  if(![url]www.error[/url]) source.clip = [url]www.audioClip;[/url]
}

That code is pretty much a memory leak, so no. But the general idea of that still does not work.