Search Unity

Debug variables inside a Coroutine (Debugger says they are out of scope)

Discussion in 'Scripting' started by Maeslezo, Jan 28, 2019.

  1. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    331
    Hi!

    I am trying to debug variables inside a coroutine, but the debugger says that the variable is out of scope.

    Any idea how to fix this?

    Thank you.

    Info:
    Visual Studio Community 2017 Version 15.7.3
    Visual Studio Tools for Unity 3.7.1
    Unity 2018.3.2f1
    Scripting runtime version .NET 4x Equivalent
    Scripting backend Mono
    Api Compatibility Level .Net Standard 2.0

    coroutine debug.png
     
  2. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Coroutines and debugging is fubar
     
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    I recommend posting a bug report, mark it with [Visual Studio]. It might get passed on to the VS Tools team.

    You could also try to report it as a bug in Visual Studio itself, but MSoft is much worse at getting back to you about bugs than Unity is.
     
  4. albertk91

    albertk91

    Joined:
    Sep 3, 2022
    Posts:
    3
    5 years later, same issue with latest VS and Unity
     
  5. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,927
    I wonder if this is due to the compiler magic involved with coroutines. And I double wonder if you wrote an actual struct/class implementing IEnumerator if it would work.
     
  6. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    I talked with some people from Jetbrains at last Unite, and they said that making the debugger work for Mono was very hard. The Mono runtime apparently didn't always pause execution when it said that it had, and vice versa. So Rider apparently has some gnarly workarounds for that. I assume it could be the same thing with VS.

    They also said that CoreCLR was a lot better on that front, so once that lands we'll probably see some improvements.
     
    spiney199 likes this.