Formerly working game not working once I added audio

I just finished my simple game. You shoot projectiles, they hit things, you get points, yadda yadda yadda.

It worked fine in Unity, built fine, installed to iPhone fine, and worked on iPhone fine.

I wanted a few sound effects to enrich the experience. I added 9 audio clips, all .mp3, none longer than 14 seconds each (most 3 seconds long actually, gotta’ love the loop feature on audio source!).

The game works fine in Unity, and in Unity Remote too (though the sound of course plays through my iMac speakers).

Now when I go to build it, Unity outputs it fine, Xcode says it built and installed it fine…BUT…

When it tries to auto play the program after installing it, the Unity splash screen pops up and just hangs there.

Now, I’m used to having to see that screen for 10 seconds the first time my app runs (thereafter it takes about 5 seconds for my iPhone to load the game when I start it).

But now that I’ve added audio, the splash screen pops up and stays there…and stays there…and stays there…for up to one minute before quitting back to the Home Screen.

Xcode says it built and installed fine. So my question is, did adding audio screw up iPhone’s ability to run the app?

I tried using uncompressed audio, compressed audio, making the program yield for 0.1 seconds after loading new clips into the audio source before playing them, not waiting any seconds when doing the same thing, etc…

I’m stumped. Does anyone have any answers or insights? Please?

The last time I checked, I’m not a swine so feel free to cast your pearls before me! :slight_smile:

Found this error code after letting it hang for like five minutes before Xcode restarted my iPhone.

*** Collection <NSCFSet: 0x2efb620> was mutated while being enumerated.

What the shmeck does that mean?

Tried it again. This time after trying to play the app on my iPhone after installation, Xcode gave me this message:

quit with Status 15.

Any thoughts?

I’m leaning towards having to rebuild my game from scratch without sounds.

I don’t have an older version of my game before I added sound, since I didn’t think that would ruin things. I’ve already tried going through and commenting out the sound playing code in the scripts as well as deleting the audio source and tracks, etc…

I’m pretty bummed, to say the least, especially since I stayed up until 4:30 a.m. yesterday morning finishing it up. :frowning: Dang, is all I can say.

I’d really, thoroughly and entirely appreciate anyone giving some help here.

Has this not happened to anyone else? The error codes, I mean?

*** Collection <NSCFSet: 0x2efb620> was mutated while being enumerated.

and

quit with Status 15

Hello KairosKinema,
could you paste some code how actually you are playing sounds. Keep in mind that only one compressed sound could be played at once (this restriction does not apply for uncompressed sounds).

You may see useful this thread: http://forum.unity3d.com/viewtopic.php?t=17416

mantasp, thanks for replying!

I did indeed see that other thread you linked to, which is why I tried my game with both compressed and uncompressed audio to see if that was the problem.

How I’m playing the sounds in my game is that I have an empty game object with both an audio source and audio listener attached, as well as my “PlaySounds” script.

Once in the game, while the player is aiming their shot I have some ambient nature sounds playing as a background. When an event occurs such as the player firing or their projectile hitting a target or the ground, etc…, those objects (ground, projectile, target, etc…) call a function in the “PlaySounds” script to play the appropriate sound, before returning to the default nature sounds.

Here is my “PlaySounds” script:

private var quiverScript : QuiverScript;
var playThis : AudioClip;
var menuAudio : AudioClip; //0
var aimingAudio : AudioClip; //1
var scoreAudio : AudioClip; //2
var missAudio : AudioClip; //3
var arrowAudio : AudioClip; //4
var onePointAudio : AudioClip; //5
var threePointAudio : AudioClip; //6
var fivePointAudio : AudioClip; //7
var appleAudio : AudioClip; //8
function Awake () {
audio.clip = menuAudio;
//playThis = menuAudio;
audio.Play();
audio.loop = true;
}
function Start () {
** var scoreObject : GameObject;**
** scoreObject = GameObject.Find(“ScoreKeeper”);**
** quiverScript = scoreObject.GetComponent(QuiverScript);**
}
function Update () {
** print(audio.clip.name.ToString());**
}
function ClipPlay (playThis : int) {
** if (playThis == 0) {**
** audio.clip = menuAudio;**
** audio.loop = true;**
** yield new WaitForSeconds(0.1);**
** audio.Play();**
** } else if (playThis == 1) {**
** audio.clip = aimingAudio;**
** audio.loop = true;**
** yield new WaitForSeconds(0.1);**
** audio.Play();**
** } else if (playThis == 2) {**
** audio.clip = scoreAudio;**
** audio.loop = true;**
** yield new WaitForSeconds(0.1);**
** audio.Play();**

** } else if (playThis == 3) {**
** audio.clip = missAudio;**
** audio.loop = false;**
** audio.Play();**
** yield WaitForSeconds (audio.clip.length);**
** if (quiverScript.arrowsLeft == 0) {**
** audio.clip = scoreAudio;**
** audio.loop = true;**
** yield new WaitForSeconds(0.1);**
** audio.Play();**
** } else if (quiverScript.arrowsLeft > 0) {**
** audio.clip = aimingAudio;**
** audio.loop = true;**
** yield new WaitForSeconds(0.1);**
** audio.Play();**
** }**
** } else if (playThis == 4) {**
** audio.clip = arrowAudio;**
** audio.loop = false;**
** yield new WaitForSeconds(0.1);**
** audio.Play(); **
** } else if (playThis == 5) {**
** audio.clip = onePointAudio;**
** audio.loop = false;**
** yield new WaitForSeconds(0.1);**
** audio.Play(); **
** yield WaitForSeconds (audio.clip.length);**
** if (quiverScript.arrowsLeft == 0) {**
** audio.clip = scoreAudio;**
** audio.loop = true;**
** yield new WaitForSeconds(0.1);**
** audio.Play();**
** } else if (quiverScript.arrowsLeft > 0) {**
** audio.clip = aimingAudio;**
** audio.loop = true;**
** yield new WaitForSeconds(0.1);**
** audio.Play();**
** }**

** } else if (playThis == 6) {**
** audio.clip = threePointAudio;**
** audio.loop = false;**
** yield new WaitForSeconds(0.1);**
** audio.Play(); **
** yield WaitForSeconds (audio.clip.length);**
** if (quiverScript.arrowsLeft == 0) {**
** audio.clip = scoreAudio;**
** audio.loop = true;**
** yield new WaitForSeconds(0.1);**
** audio.Play();**
** } else if (quiverScript.arrowsLeft > 0) {**
** audio.clip = aimingAudio;**
** audio.loop = true;**
** yield new WaitForSeconds(0.1);**
** audio.Play();**
** }**
** } else if (playThis == 7) {**
** audio.clip = fivePointAudio;**
** audio.loop = false;**
** yield new WaitForSeconds(0.1);**
** audio.Play(); **
** yield WaitForSeconds (audio.clip.length);**
** if (quiverScript.arrowsLeft == 0) {**
** audio.clip = scoreAudio;**
** audio.loop = true;**
** yield new WaitForSeconds(0.1);**
** audio.Play();**
** } else if (quiverScript.arrowsLeft > 0) {**
** audio.clip = aimingAudio;**
** audio.loop = true;**
** yield new WaitForSeconds(0.1);**
** audio.Play();**
** }**
** } else if (playThis == 8) {**
** audio.clip = appleAudio;**
** audio.loop = false;**
** yield new WaitForSeconds(0.1);**
** audio.Play();**
** yield WaitForSeconds (audio.clip.length);**
** if (quiverScript.arrowsLeft == 0) {**
** audio.clip = scoreAudio;**
** audio.loop = true;**
** yield new WaitForSeconds(0.1);**
** audio.Play();**
** } else if (quiverScript.arrowsLeft > 0) {**
** audio.clip = aimingAudio;**
** audio.loop = true;**
** yield new WaitForSeconds(0.1);**
** audio.Play();**
** }**
** }**

}

And here is an excerpt from the “GroundHit” script calling the “ClipPlay” function from the “PlaySound” script:

private var playSounds : PlaySounds;
function Start() {
var soundObject : GameObject;
soundObject = GameObject.Find(“AudioPlayer”);
playSounds = soundObject.GetComponent(PlaySounds);
}
function OnCollisionEnter(hit : Collision) {

** playSounds.ClipPlay(3);**
** screenNav.screenShown.texture = screenNav.missShot;**
** yield new WaitForSeconds(2);**
** playSounds.ClipPlay(1);**
}

So as you’ll remember from the earlier code, calling the function “ClipPlay” with the (3) next to it would execute this code from “PlaySounds” (note that in order to avoid having two clips play at once–even if they are uncompressed audio just to be safe–I wait for the audio.clip.length to fully play before switching back to the ambient nature sounds which is called “aimingAudio” below):

} else if (playThis == 3) {
** audio.clip = missAudio;**
** audio.loop = false;**
** audio.Play();**
** yield WaitForSeconds (audio.clip.length);**
** if (quiverScript.arrowsLeft == 0) {**
** audio.clip = scoreAudio;**
** audio.loop = true;**
** yield new WaitForSeconds(0.1);**
** audio.Play();**
** } else if (quiverScript.arrowsLeft > 0) {**
** audio.clip = aimingAudio;**
** audio.loop = true;**
** yield new WaitForSeconds(0.1);**
** audio.Play();**
** }**

This is typical of how all the sounds in my game are played: an event occurs, “ClipPlay” is called with the appropriate integer in parentheses to activate the desired sound, etc…

Can anyone see something I’m doing wrong?

Still no ideas?

Anyone from Unity?

Anyone not from Unity?

I don’t recall seeing a topic stump everyone before.

I must be the only one with these error codes from Xcode?

Hello,

I also am having some weird issues regarding adding sound then the build getting… “corrupted” is the only word I can use to describe at the moment.

In my case I have been working on a mod of the iPhone matching game sample. When I play the game in Unity all works just fine. I then build the game from scratch ie. not overwriting any files and it builds fine with no issue and starts to run on my iTouch. The first part of my app works fine but when the script resets the output it gives me is different from what the Unity Game test screen gives me. It’s really strange. I’ve tried building the app in 2.0 through 2.1.1 and I get the same result every time.

The only thing I can think of at the moment is I have some textures in the app which are not power of 2?

I should also note all of my sounds are uncompressed.

I had plenty of textures that weren’t power of 2 in my app and it worked fine on my iPhone.

It wasn’t until I added sound that it stopped working on my iPhone.

Well seems like we are the only two struggling with this… as I keep messing with my own problem I’ll let you know how it turns out.

Basically my current theory is that I simply have too many objects loaded in my scene at once at the moment and the lack of memory available is causing weirdness…

The basis for this theory is that the app worked fine, I assigned about 100 sound files into my scene and now it still works on my mac but not on the iTouch. I have also noticed a marked amount of lag in my app after loading the sounds. I traced my code and basically what the iTouch is doing is skipping an increment in my for loop.

for instance…

for (i=0;i<something;i++)

the i++ is not happening the second time around but it is the third. Weird eh… At the moment I’m trying to figure out how to dynamically load my 200 prefabs into my scene via code instead of having them all in at once out of view. If anyone can help me with this I would much appreciate it.

I believe the right track is … Instantiate(Resources.Load(“somefile”)) but I have not been able to make this work yet as it keeps saying the object its looking for is null >.<.

======
EDIT:

So yeah I tried all kinds of things and finally I removed every last non power of 2 texture and guess what… bang its fixed. Non power of 2 = 4 letter word for the iTouch/phone apparently. I hope you get your issue fixed. I would look into the textures too as my problem seemed to be completely unrelated but it still fixed it. :lol:

But I had non-power of 2 graphics working on my iPhone before I added sound.

Hmmm. So if you took out, say, 480x320 images, what did you replace them with? 320x320 with pillar box matting on the sides?

And your sounds work now?

320x320 isn’t power of two. You’d replace 480x320 with 512x512…pad out the unused space with empty pixels.

–Eric

if you add wav, also remember that they will hog your memory as well in the size they are, so keep them as small as possible.

if you own bliprobs enhancement pack, try to use its memory reading capabilities to get some more stats and find out when you reach the border.

up to 40mb you are save on all devices.
above you require an iphone or 2nd generation ipod touch to remain save as the 1st gen ipod touch will start to fail between 45 and 60mb depending on the situation

Right after I posted that I realized I wasn’t talking power of two with 320x320.

I went into Photoshop, took my 480x320 image, made the canvas size 512x512, filled in the empty area with black, imported that image back into Unity, set my GuiTexture size to 512 width and 512 height, and the pixel offset to X = -256 and Y = -256 and voila, my original images are now power of 2 and displaying perfectly.

We’ll see how this works with building and installing, though.

Congratulations on solving your problem!

Update:

After removing non-power of 2 images, my game builds and installs fine. Wow!

Funny thing is, my game worked with non-power of 2 images UNTIL I added audio. Hmmm.

Anyway, lesson learned: non-power of 2 images = BAD BAD BAD!!!

I would guess that the textures were taking up excessive amounts of RAM because of being expanded, and the audio pushed it over the edge.

–Eric