(back to blog)

On Visual Studio Tools for Unity and Console Redirection


Using Visual Studio when working with Unity is awesome and Visual Studio Tools for Unity takes the comfort even further. Since Unity's 5.2 upgrade, VSTU comes integrated with VS. Though with this integration, the developers took away some of the flexibility.

For instance, I would like my VS to have a very clean view. VSTU's relaying Unity's Debug.Log's to VS's console spoiles this neatness a considerable amount, since it opens and re-opens console window without my permission, as log prints keep coming. Before 5.2 integration, it used to have a nice configuration menu wihtin Unity, where one could toggle this feature. Now, appearently, there is not.

(EDIT): There is now with version 2.3. The code below is unneeded now.

When I asked, the developer was kind to give the answer, which is an editor script that toggles console redirection:

    /* With the native integration we don't have a menu to setup options anymore. 
    That's because the majority of VSTU options are now directly available within Unity project settings.
    But this is not the case for the console redirection. You should do something like this with 
    an Editor script to properly setup what you want: (only once, this setting is global). */
    using UnityEngine; 
    using SyntaxTree.VisualStudio.Unity.Bridge.Configuration; 
    using UnityEditor;

    public class Configuration : MonoBehaviour 
        [MenuItem("VSTU/Enable or Disable SendConsoleToVisualStudio")] 
        static void SwitchSendConsoleToVisualStudio() 
            var cfg = Configurations.Active; 
            var status = (cfg.SendConsoleToVisualStudio = !cfg.SendConsoleToVisualStudio) 
              ? "enabled" 
              : "disabled"; 
            EditorUtility.DisplayDialog("VSTU", "SendConsoleToVisualStudio is now " + status, "OK", "");