You don’t use Unity 3D, it uses you

After seeing how so many people are picking up game engines like Unity 3D and Unreal Engine for their smaller scale game projects, I decide to do a little more research on what would be required to use one for an upcoming game idea of mine.

I chose Unity 3D to start with and downloaded the free version, and was able to run the editor tool and start playing with it pretty quickly. The interface was closer to something like 3DSMax or Blender in that content creation seemed to be top priority, with behavior and the programming parts secondary. On top of this, I was surprised that Objective-C wasn’t supported natively, though there was some sort of way to bridge this language and use it together with Unity.

Wondering how I could develop a platform specific (iOS in my case) game with the engine, I found there is a separate set of APIs which mirror those on the platform, and you actually generate a XCode project with the relevant files, and use that when you submit to the App Store.

This entire process was completely the reverse of what I am used to, making a project in XCode and just importing libraries as needed.

After some consideration, I decided to put Unity 3D on hold since it would require such a major shift in development style. Clearly, if I want to make a high quality 3D game an engine like this is necessarily, and there is also the extra advantage that I can easily port it to other platforms. However, the game I have in mind can probably be done pretty well in basic 2D, so I tentatively decided to prototype it first in the simplest possible way.

One of the reasons I made this decision is because my time budget is pretty tight. Had I been back in college when I had much more free time, it might have made more sense to just spend a few solid weeks learning Unity 3D. But for my current situation, I am not sure if that is worth my time. Also, I generally like to focus on writing gameplay and AI, with less of an emphasis on visuals, so I try to plan things so I can spend the most of my time on these elements.

While it’s true that many games these days decide to use a 3D engine just to look cool or extra realistic even when the gameplay doesn’t require it (ex: Smash Brothers), in my case I am not sure if the extra time to use 3D is worth it.

Lessons learned doing sound on iOS – the real story

A few days ago I wrote an article about using sound effects in iOS games. Just today I was doing some more testing and realized I had made a major mistake, and some things I said in that post were wrong. In this post I’ll let you know what I had did wrong.

I alluded to a single line change that would allow playback of MP3 files. Here is the specific line:

NSString *audioFilePath = [[NSBundle mainBundle] pathForResource:sampleName ofType:@”caf”];

I had simply changed the “caf” to “mp3” and since I was getting sounds I assumed things were working. The weird staticky sounds I got I explained by saying that several of the same sound were colliding and causing such an effect. Though sound collision can be a problem and sometimes it might make sense to have several variations of a sound effect, what appears to have been actually happening is that OpenAL didn’t know how to process MP3 and so it was just generating random noise.

After a tried a few different .MP3 files and they all sounded pretty much the same, I finally realized what was going on.

The solution was to return the code to use “caf” files, and use a line like the below to convert MP3 files to CAF files.

> afconvert -f caff -d LEI16@44100 chop.mp3 chop.caf

After doing this, my sounds finally started playing properly. I did find some strange effects that occur when sounds overlap quickly, but they were more subtle.

One additional step that is good to know is you will need to manually tell the .caf files you added to your project that they need to be included with the bundle that gets copied to the device. You can do this by dragging the file under XCode’s Build Phases => Copy Bundle Resources. I didn’t notice this problem for MP3 files, as it seems smart enough to add the to this list automatically.

The strange thing is I would expect OpenAL to throw an error somewhere instead of just spitting out noise. So either this set of APIs is pretty badly designed, or there is some code in AudioSamplePlayer that isn’t handling things properly. Either way, I got things working so not going to pry any deeper at this point.