If you’re like me and use both Visual Studio and Unity, how many times have you accidentally tried to run the game from Visual Studio?
Unless you’ve bought UnityVS, there’s a dead simple (and free) way to launch your Unity scene from Visual Studio and get that feeling of warmy goodness from all the seamlessness.
Ingredients
- Visual Studio (obviously)
- Unity (obviously)
- AutoHotkey
Steps
- Create a new C# Winforms project called UnitySwitcher (or whatever)
- Add the Autohotkey to the project
- Set its Copy to output Directory to Copy if newer
- Delete form that was added automatically
-
Update
program.cs
to[STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); System.Diagnostics.Process.Start("launch-unity.ahk"); // new }
-
Add this AutoHotkey script to the project as launch-unity.ahk
IfWinExist, ahk_class UnityContainerWndClass { WinActivate Send ^p ; sends Ctrl+P } else { MsgBox, 64, Unity is not open. Please open the project to run from Visual Studio. }
- Add your existing project to the solution, it should be called Assembly-CSharp-vs.csproj
- Ensure UnitySwitcher is set as your startup project
You can grab the gists of the launch-unity.ahk
and program.cs
at https://gist.github.com/jaywick/11083565
Extra Notes
The good thing about this method is that it leaves the source.sln solution file untouched. If there’s any issues or bugs feel free to hit me back on the gist link or here in the comments.
Happy coding.