Unity 3D – First Impressions
One of the things I’ve been dying to play around with lately is Unity 3D, the game engine. I’ve worked in game mods before, but this was years ago and I functioned in the capacity of artist or sound engineer. Well time goes by, and I’ve become a pretty serious coder.
I had the good fortune of speaking with Joe Santos at the Unity booth at the recent GDC, who gave me a little walkthrough of how the tool works, as he was quite knowledgeable on the subject. Through the remainder of the show, I kept hearing people speak of Unity, so I finally got around to downloading the evaluation version, and I have to say my first impressions are good.
Unity comes with a pretty nice IDE, and a scripting tool that would not intimidate anyone who has worked in Flash or simillar tools.
The IDE
The IDE is very visual, and nice to work in. I believe this is one of the strongest points in favor of Unity. Most of the action takes place in a game view, and a scene view. Scene view is where you actually move things around and select objects – it can be rendered as a mesh view, textured, or a combination of both. The game view is where you can review the status of your scene, and it comes with play/pause buttons. Enabling the animation in your scene is as simple as hitting play. One awesome feature is that you can actually tear off that game window and stick it on another monitor if you like. I found this good because I would sometimes get confused when reviewing the game action and go to move my pointer over to the other parts of the IDE to change a setting. Having the game view torn off just separated it more clearly in my head.
Of course you can select many configurations for the scene view, and how you choose to arrange it will likely have to do with how much screen real-estate you have. More is always better.
You’ve got your gizmo in the scene view that allows you to quickly look at your objects from any angle. You can grab the objects by their meshes and move, rotate, scale them as you wish and this part works a lot like 3DSMax (scale on any axis by selecting it, or scale uniformly by mousing on the middle of the gizmo). Use the mouse wheel to zoom in and out. Speaking of finding and grabbing objects, there is a great way to do it in Unity.

Unity Hierarchy Panel
In the IDE there is a panel called the Hierarchy. This is a list of all the objects in the scene, and a quick visual reference as to how they relate to each other. Using it, you can quickly find any item in your scene (which can get pretty full of objects). In the Hierarchy panel, you can just select the object, then when you mouse over the scene display, press “F” and the scene will automatically move to the object and center on it, and the object will be selected. This is a big lifesaver. As you get more used to Unity, you’ll find that the Hierarchy panel can also be used for parenting one object to another very simply, or to attach a script to an object. Scripts control the behavior and logic of your game.
A second important panel is the Inspector. This panel is very similar to the panel in Flash of the same name. All objects, behaviors and such in your scene have properties associated with them. These properties are exposed by the inspector and can be manipulated there. One nice thing is that these properties remain exposed even while the game is in “play” mode, and you can actually change them and see the result on your objects right away. This makes it very easy to tweak small points in your animation.
The other major panel is the Project panel. This is where all the assets of your scene get revealed. I have to say that Unity has one of the most brilliant ways of handling asset imports that I have seen. Essentially, you set up an asset folder in a particular location, and if you drag anything in there in your OS that is supported by Unity, it is imported! Unity seems to be able to dynamically notice changes in this folder. For instance, if you have a texture in there that is applied to a model, and you edit that texture in photoshop, as soon as you save it the texture is updated in Unity, with no need to refresh. Very nice and simple. One nice thing I noticed about the project panel is that all of your scripts get placed in a folder there. This is pretty handy, because I can easily imagine that your scripts could get pretty scattered around otherwise, and be hard to find.
- Unity Inspector Panel
Between these three panels of the IDE, you can do quite a lot.
Scripting
Scripting in Unity is accomplished via some very well known languages, Javascript and C#. There is also another one called Boo, but I must confess I have no idea where that language comes from.
You can script in any editor you wish, and you can set a preference as to what editor you like. Seems like Unity originally had a proprietary scripting tool, but it now ships with Scite, which is quite well known, and a good editor overall. I’ve heard that someone updated FlashDevelop to work with Unity, and that tells you something about how popular the engine is getting with Flash people. I can see why.
The scripting reminds me a whole lot of AS2. In fact a lot about Unity reminds me of the way we did things in Flash 7 or 8. In other words, you attach your scripts directly to your game objects, and they have the ability to call functions based on frames passing in the scene. Depending on how many frames pass per second, you can create animation within the function. There are yet more parallels – prefabs in Unity are a lot like MovieClips, just more powerful and all 3D-like.
The “update” event of Unity is a lot like an EnterFrame in Flash, however Unity (being focussed on games) has the aditional nice feature of a Time class that keeps track of DeltaTime – the amount of time that has passed between frame executions. This is very handy, as I’ve seen a lot of code written to keep track of this and accomodate for it in animations to make the animation smooth-looking.
There are events and event-handlers (and these must start their names with “on”). Functions are defined with curly-braces as one might expect. Classes and script names are capitalized.
Anything that can be attached to a game object, such as scripts, are known as components in Unity. Many game objects have components attached to them automatically, and these can be accessed by member variables to affect certain behaviors on the object with your script. Multiple components can be attached to one game object, and interestingly there is a getComponent method that can be used by any of those components to find another component attached to the same object. The calling component can then execute a method on the found component. Not sure how I feel about that, as it seems a bit messy and an odd way to handle scope, but we’ll see how I like it as I play around with it.
Earlier we mentioned that you can parent one object to another in the Hierarchy panel. This is handy in the script world as well, because there is definitely a displaylist at work in Unity. Essentially all game objects exist in a hierarcy – some objects are parented to others, all the way up to the scene they exist in. Every object has a Transform component associated with it that keeps track of position and scale. Using the hierarchy and the transform components associated with them you can iterate the displaylist and find any game object. This is powerful.
You can also find game objects through a tagging system (which essentially is the name of the object). Hard to say what might be the better way of doing things, but I think I favor the first method, as it seems less prone to human error that might be introduced through the Inspector panel. As mentioned, once you’ve found a game object, you can find any components associated with it, and call methods in them.
Lastly you can also get references to other game objects through events handled. In other words, much like AS3 if you handle an event, you can look inside that event to see where it originated from. Now you have your object reference, you can look for components on the object, and execute methods of the components. (Components should be thought of as classes)
Handling of variables in your component-classes seems pretty straightforward; variables declared in functions are accessible only to functions. Variables declared outside of functions are member variables. Member variables can be marked private, or can be static. Note that you can not edit private variables in the inspector while the scene is playing, unlike other variables.
Make a new game object dynamically with the Instantiate keyword. I wonder if a factory class is a possibility? For that matter I wonder about a lot of things like that, it’ll take a while to figure out the best way of organizing code.
Logic, loops, etc.
It seems like loops and logic work pretty much how one might expect them to in a JS based language. The one thing I hadn’t seen before was the “yeild” keyword. This allows a method to continue from the line after the yield keyword the next time it is called. Very interesting. It means you can essentially change the behavior of a method on a per-call basis depending on how far through the method the instructions are executed. Looking forward to playing with that.
Compiling
Unity compiles all scripts to .NET dll files. These get jit compiled by the player at runtime. This makes for wicked-fast javascript (or just a little chuggy C++). This is plenty enough speed for some very good games.
And thats the Oddly first view of Unity. Looks like piles of fun with a not-so-heavy entry point for anyone who has worked in an ECMA language, and perhaps has some familliarity with tools like Max or Maya.
I’ll let you know how my experiments go!




