Thursday, September 15, 2011

Multiple Instances Of Unity3d

Whenever I program in VS 2010, I normally have multiple instances of the studio open. Some times I use the extra instances because they are dependant solutions that I need quick access to, sometimes I have some good tutorials or example projects that I want to quickly reference, run and debug.

I thought I had lost this when I started working in Unity3d, and I never needed more than now.  Although I can reference the code from other project easily enough using MonoDevelop, the code is only half the story.  Often, the scene can tell you more than the actual code can.  And although I've been programming in it for a while now, I still find the plethora of Unity tutorial online to be invaluable in my endeavour to better myself.

It turns out it's absolutely possible to do this.  Just not as straight forward as you would launch it normally. There's a nice command line page for unity here, the option that is important for us right now is the -projectPath.

Now from the terminal, I type:

/Applications/Unity/ -projectPath /Users/username/Unity/ProjectName

Yep, that works! I now have another Unity instance right next to my previous one.  Now this is somewhat cumbersome as I don't want to go to the terminal every time I want to launch my project.  I now have the habit of creating a small batch file in each of my project that can automatically launch Unity in a separate instance if need be.

Using nano, I would normally go in my project directory and edit a Launch.command file with the following:

/Applications/Unity/ -projectPath /Users/shadhex/Documents/Unity/ProjectName/&

The .command extension insures that I can launch the script from Finder.  The & lets the application launch in the background so that I can close my terminal window without shutting down Unity.

Hopefully that helps all the learn by example type coders out there!