Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Changing Script editor through code different to Editor UI

Discussion in 'Editor & General Support' started by SimonDarksideJ, Jan 22, 2016.

  1. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,683
    have an interesting problem / observation

    If I add a new code editor through script by setting the "kScriptsDefaultApp" and "kScriptEditorArgs" Editor properties, it behaves differently that when you set it through editor ui.

    For example:
    If I setup VSCode through the editor pointing to:
    "C:\Program Files (x86)\Microsoft VS Code\code.exe"

    Then this runs the program direct without issue.

    If however I do (cut short for simplicity)
    EditorPrefs.SetString("kScriptsDefaultApp", "C:\Program Files (x86)\Microsoft VS Code\code.exe");

    This causes a new process to be called and then the app is launched.

    Any ideas why or how you can configure it to just run the exe instead of starting a new commandline process to start it?
     
    lucbloom likes this.
  2. lucbloom

    lucbloom

    Joined:
    Mar 27, 2020
    Posts:
    32
    I was trying to accomplish the same thing. Unity opens scenes and prefabs in Visual Studio (as text) when I select it as the External Script Editor. When I solve that by selecting "Open by file extension", it doesn't generate a correct project (reverts to a non-Unity app, e.g. "Attach" becomes "Run") and double-clicking an error in the console doesn't jump to the correct line anymore.

    Anyway, I was trying to make a tool button that easily switches between the 2 states. Sad to hear it's probably not going to be easy either. Maybe 6.5 years later it "just works"?
     
  3. lucbloom

    lucbloom

    Joined:
    Mar 27, 2020
    Posts:
    32
    Yes, it works now!
    Code (CSharp):
    1.         EditorGUILayout.BeginHorizontal();
    2.         bool isOpenByExtension = EditorPrefs.GetString("kScriptsDefaultApp", "").IsNullOrEmpty();
    3.         GUILayout.Label(isOpenByExtension ? "Now using Extensions" : "Now using Visual Studio");
    4.         if (GUILayout.Button(isOpenByExtension ? "Use Visual Studio" : "Use Extensions"))
    5.         {
    6.             EditorPrefs.SetString("kScriptsDefaultApp", isOpenByExtension ? "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/devenv.exe" : "");
    7.         }
    8.         EditorGUILayout.EndHorizontal();
    9.