Why Unity is my new favorite development tool
Like many developers, I've used a lot of different development tools over the years. My particular focus is on cross-platform development; we do a lot of Mac/Windows (and occasionally Linux) apps in REALbasic, and we've worked out methods for using the same C++ code on iPhone and Android.
For many purposes, REALbasic is quite nice. The language is clean and sensible, the IDE is the best I've ever seen, and it really does a good job of cross-compiling between platforms. But it has its limitations: For example, it doesn't compile to mobile devices, and most likely never will. Also, while it used to have a decent high-level 3D framework, they removed that from the product a few years ago to focus more on business-oriented apps.
So when my 9-year-old wanted to learn more programming (having already taken Scratch about as far as it can go), I was faced with a dilemma. He's interested in games, of course, and game programming in REALbasic isn't as easy as it used to be. He's also excited about the idea of someday making his games run on the iPhone and iPad, which RB will never do. We spent a bit of time last summer teaching him Objective-C and Cocos2d for the iPhone, but it was painful — that's one crufty language combined with an even cruftier IDE.
Then, a few weeks ago, I rediscovered Unity, and everything changed.
I'd run into Unity before, when looking at various 3D development frameworks that we might want to use someday in our real work. That need didn't materialize, and at the time, Unity was just one of several half-decent frameworks we looked at. It left just enough of a positive impression that when I was again feeling the need for something better suited to my needs than REALbasic or Cocoa, I took a deeper look. This time, I was blown away. Unity rocks.
Unity, how do I love thee? Let me count the ways:
1. It compiles to virtually everything, including Windows, Mac, Android, iPhone, Wii, Xbox, and PS3. Oh, and you can also publish your game to the web (using the increasingly popular Unity browser plug-in). That's an incredibly wide reach for any dev tool.
2. As a development environment, it runs on both Mac and Windows — and the Mac version doesn't suck. That puts it way above most of the competition in my book.
3. The performance and quality are top-notch; it's used in real top-tier titles by folks like EA and Disney.
4. But the cost is quite reasonable. It comes in several versions, but the free version for personal use is quite generous, and will be more than sufficient for most hobbyists. If you need the pro tools, it's still pretty reasonable: $1500 for the base, with a few add-ons for platform-specific tools. That's about the cost of a development machine, and if you're doing professional work, it's a minor expense.
5. The IDE is really nice. You can position objects in the 3d scene with the mouse, adjust properties and scripts, and then click the "Play" button to try it out. You can inspect and adjust properties even while the game is running, then click "Stop" to go back to the initial state.
6. The general approach to taming the complexity of 3D game development works really well. Basically it's this: each object (whether that's a visible game object, or something more abstract like a camera) has any number of "Components" associated with it. These are like add-ons (or in programming terms, mix-ins) that give the object additional properties and behavior, all of which you can easily access in the inspector panel. Components can include scripts, which are bits of JavaScript or C# code which are invoked in an event-driven way.
7. Scripts can define public properties right in the script source. These appear in the Inspector under that script component wherever the script is used. These properties can be of several types, including numbers and references to other objects. This is an incredibly easy and intuitive way to adjust script parameters, or connect your scripts together.
8. The organization of objects, components, and scripts result in the most effective code reuse I've ever seen. Scripts in Unity really are independent bits of functionality that can be mixed and matched at will. One trivial example may give a hint of the flavor: there are several standard camera scripts, including "Smooth Follow" and "Smooth Look At". Each of these has a Target property that tells the script what to follow or look at. You can use just the Follow script, and the camera will faithfully track the target without changing its angle, like in an RTS or 2D platformer. Or you could use just Look At, and keep the camera in place while it looks at the target wherever it goes. Or use them together, and the camera will smoothly follow an object while also keeping it in the center of the view, like in a typical third-person game. This only scratches the surface; other scripts control vehicles, drive characters, handle explosions, do "fog of war," and so on — and you can use any of them in pretty much any combination you want. These are the reusable software components we've been hearing about (but rarely seeing in practice) for decades.
9. The documentation is outstanding. Not to gush, but it really is the best I've ever seen for any programming environment. You can view any component from the perspective of a level designer, or from its scripting API; and in the scripting view, you can switch between JavaScript or C#. That switch includes the code examples -- and everything has at least one code example. It's all searchable and hyperlinked, and the text is well written and clear. The amount of time that must be put into these docs is staggering.
10. The user community seems to be great, too, though I have to confess that the environment is so well-designed, and the docs so clear, that I've hardly had to look in the forums for anything yet.
The more I play with Unity, the more I like it. It's certainly what I'll be teaching my son to program in from now on. I've already exposed him to it a little, and he picked up the key concepts (including how to manipulate objects in the scene editor) with no trouble at all.
I don't know yet whether we'll have opportunity to use it in our paying work here at Luminary Apps, but we might. It's good for more than just games; it could also make a decent platform for kiosks, simulations, multimedia apps, etc. And while I really like our internal 2D C++ sprite framework, if we do need 3D at some point — or want to port anything we've written to consoles — Unity will be the first tool I consider.
But I realize that I'm still in the romance phase of my relationship with Unity. Perhaps in time I will run into hidden gotchas and shortcomings that make it seem less shiny. What do you think? Is Unity really the bee's knees it appears to be, or not? And if not, what do you like instead? Feel free to chime in below.