Break when watched variable has changed

Oliver Marshall 1 Reputation point
2021-10-16T15:36:11.313+00:00

Hi all

Is there a way to set the VS debugger to break when a watched variable has changed?

I use VS with Unity 2020 and I've spent ages trying to find where one of my variables is changing. I've tried popping debug.log code in at various places but I wonder whether there's a way to set a watch on the variable and just run the code and have VS break when the variable changes value.

Is something like that possible?

Olly

Developer technologies Visual Studio Debugging
Developer technologies C#
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. RLWA32 49,536 Reputation points
    2021-10-16T15:43:37.2+00:00

    Set a data breakpoint -- Set data breakpoints (native C++ only)


  2. Oliver Marshall 1 Reputation point
    2021-10-16T15:55:43.297+00:00

    Thanks. I didn't know about data breakpoints.

    The link is for C++ whereas I'm using C#.

    It does appear that c# support for Data Breakpoints was added to VS 2019 v16, however I'm running 16.11.5 and it remains greyed out for me.

    Olly


  3. Anna Xiu-MSFT 31,056 Reputation points Microsoft External Staff
    2021-10-18T09:54:11.217+00:00

    Hi @Oliver Marshall ,

    Welcome to Microsoft Q&A!

    As the document states: Troubleshooting data breakpoint errors,
    The support for managed data breakpoints began in .NET Core 3.0. It is currently not supported in .NET Framework, versions of .NET Core under 3.0, or versions of .NET under 5.0.3.

    For any suggestions about this feature, please report it via Help > Send Feedback > Report a Problem in the IDE or in the Developer Community.

    Sincerely,
    Anna
    *
    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.