Search Unity

Unity Stops Responding When Play and Attached to Visual Studio

Discussion in 'Scripting' started by OliverTheLove, Nov 2, 2020.

  1. OliverTheLove

    OliverTheLove

    Joined:
    Jun 26, 2016
    Posts:
    24
    Hello!
    I have an issue where if I have attached Visual Studio to my game projects, and I hit play in Unity, Unity stops responding indefinitely and I need to shut it down via the Task Manager. It doesn't help detaching from VS or shutting it down.

    Is there some way that I could debug it? On this page there is some troubleshooting, but from what I understand it is mostly about VS hanging, and not Unity?

    Edit: I can debug if I hit play first and attach after game has started

    Specs:
    Unity Version - 2019.3.4f1 HDRP (and URP that I am downgrading into on another branch, big mistake, haha)
    Microsoft Visual Studio Community 2019 - Version 16.7.7

    upload_2020-11-2_21-19-17.png
    Can't pause program to see where it might have hung.
    upload_2020-11-2_21-20-29.png
     
    Last edited: Nov 2, 2020
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Looks like Visual Studio's debugger has paused your process and is holding it up. If you press the red square in Visual Studio (or the green continue button) Unity can continue.

    Given that it doesn't seem to be paused on a breakpoint - I wonder what settings you have in your VS debugger.
     
  3. OliverTheLove

    OliverTheLove

    Joined:
    Jun 26, 2016
    Posts:
    24
    Yeah no, I pressed pause there manually to see if I can see if there is any code running. Visual Studio is just attached and not paused when Unity freezes.
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Gotcha. Yeah it's most likely native C++ Unity Editor code running that the C# debugger can't handle.

    How quickly does your game start up when you press play without the debugger attached?
    What happens if you attach the debugger while the game is playing instead?
     
  5. OliverTheLove

    OliverTheLove

    Joined:
    Jun 26, 2016
    Posts:
    24
    Oh yeah, I forgot to mention that, I can attach to Unity with the debugger if the game has started :) Then I forget that I am attached after I have debugged a bit and click play and then I need to restart again, haha.

    It takes me ~4 seconds to start up without debugger.
     
  6. OliverTheLove

    OliverTheLove

    Joined:
    Jun 26, 2016
    Posts:
    24
    Did that information help you with anything? :) @PraetorBlue
     
  7. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Nope haha. Sorry I have no idea what the problem is.