Search Unity

Launching game in standalone with VS debugger attached (early enough to break in Awake)?

Discussion in 'Scripting' started by s_guy, Aug 28, 2018.

  1. s_guy

    s_guy

    Joined:
    Feb 27, 2013
    Posts:
    102
    I want to launch a standalone build with VS debugger attached as early as possible, so it can hit a breakpoint in Awake. Obviously you can attach the debugger before hitting play in an editor session, but you may have a bug that only occurs in standalone, or be working with features that only apply in standalone.

    I'm using Visual Studio 2017 and Unity 5.6.

    I've tried several options, but none worked out. Some examples:
    1. VS doesn't seem to be able to launch Unity builds directly.
    2. System.Diagnostics.Debugger.Launch() results in a "not supported" error message by Unity.
    3. Awake isn't allowed to be run as a Coroutine, but I can yield in an IEnumerator Start, while waiting for System.Diagnostics.Debugger.IsAttached. Unfortunately, VS reports the breakpoint will never be reached, and it does not break in practice. (And even if that worked, it still doesn't get me to as early as breaking in Awake.)
    Anyone have a solution or lead?

    Thanks!
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,990
    My tip: add an empty scene that loads first with just a „launch“ button waiting for you to press it which then does all the actual launch of the app. You can then comfortably attach debugger session in this prelaunch scene and then launch. However you may have to do some refactoring to make this work.
     
    s_guy likes this.
  3. s_guy

    s_guy

    Joined:
    Feb 27, 2013
    Posts:
    102
    @SteffenItterheim It's a good tip. I was already using a "pre game" startup scene where I handled various game start behavior. After adding a "pre-pre game" debugger attachment scene, the bug doesn't manifest. I can leave it like this, but would be nice to diagnose what was causing the problem.
     
  4. s_guy

    s_guy

    Joined:
    Feb 27, 2013
    Posts:
    102
    Anybody have ideas about this one? Even with the given workaround, it would be generally useful to know how to launch a Unity standalone build from Visual Studio with the debugger attached.