Search Unity

Question Pause all Audio when debugging

Discussion in 'Audio & Video' started by keinerFuerAlle, Jan 10, 2022.

  1. keinerFuerAlle

    keinerFuerAlle

    Joined:
    Apr 24, 2020
    Posts:
    6
    Hey there,
    is it somehow possible to pause all AudioSources when entering debug-mode?
    Right now, my AudioSources just keep playing when the debugger stops at the code, what causes the music to get out of sync with the code that is currently executed.
    Since I am working on a rythm game, this is quite annoying...
    So does anybody know if there is a way to keep the audio in sync with the code/pause when the debugger stops somewhere?

    This might even be a bit tricky, since I guess the Audio playback is asynchronous to the other code execution, but I think there needs to be some way here...

    Thanks a lot for any help here!
     
  2. The_Island

    The_Island

    Unity Technologies

    Joined:
    Jun 1, 2021
    Posts:
    502
    Probably what you are looking for is Debug.Break(). As you said, the Audio playback is asynchronous so maybe not perfect but I am pretty sure, it is better than a normal breakpoint for your case. At least it should. Don't hesitate to tell me if I am wrong :)
     
  3. keinerFuerAlle

    keinerFuerAlle

    Joined:
    Apr 24, 2020
    Posts:
    6
    Hey thanks for the reply and sorry for my late answer, but that actually does the trick, so thanks a lot!
    Is it maybe possible to configure an ide (rider, in my case) to use a custom method for debug breaks (so I could say, the ide should always use debug.break for its breakpoints). I think this might be a cool feature, but dunno if such a thing exists..
     
  4. van800

    van800

    JetBrains Employee

    Joined:
    May 19, 2016
    Posts:
    73
    Ok, it can be done.
    1. Add the following class to your codebase:
    Code (CSharp):
    1. using JetBrains.Annotations;
    2. using UnityEditor;
    3. using UnityEngine;
    4.  
    5. namespace Util
    6. {
    7.     public static class RiderUtil
    8.     {
    9.         [UsedImplicitly]
    10.         public static T Log<T>(T s)
    11.         {
    12.             // just  Debug.Break(); would work if the brakepoint is on the main thread
    13.             EditorApplication.delayCall += () =>
    14.             {
    15.                 Debug.Break();
    16.             };
    17.          
    18.             return s;
    19.         }
    20.     }
    21. }
    2. Right click on a brakepoint and to "More" link inside
    Add a call to Util.RiderUtil.Log("test") to "Evaluate and log" of the brakepoint:
    upload_2022-1-20_15-47-56.png

    When the brakepoint is hit, that code would get called and Editor would pause.
     
    Last edited: Jan 20, 2022
  5. van800 likes this.
  6. van800

    van800

    JetBrains Employee

    Joined:
    May 19, 2016
    Posts:
    73