Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Physics Debug Visualization

Discussion in 'Physics Previews' started by MortenSkaaning, Nov 21, 2016.

  1. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    Welcome to the feedback forum for the Physics Debug Visualization.

    What is the Physics Debugger?

    It can sometimes be hard to tell what objects in your scene should and should not be colliding, especially when the Render and Collision meshes are out of sync. To help you quickly inspect the collision geometry in your scene we’re adding a debug view mode for physics collision geometry to let you spot problems right away.

    How Can I Get It?

    Download Windows and Mac Editors
    [5.5.0f3]: http://beta.unity3d.com/download/22a2ba31cb97/public_download.html
    [5.5.1p1]: http://beta.unity3d.com/download/7bef31968871/public_download.html

    This tool is available in the Editor by selecting Window > Physics Debugger from the main menu. The tool is intended to help you quickly inspect the physics world and profile common scenarios. Feature development will be incremental and additional features such as raycast support are planned.

    When you first open it, the tool lets you quickly select GameObjects with collision geometry and can also highlight simulating Rigidbodies for debugging physics performance issues.


    From this window, you can customize visual settings and specify if there are certain types of objects you want to see or hide.



    Here we can take a look at some features that enable control of the filtering and presentation of found Colliders



    A small overlay also appears in the corner of the scene view with further options.



    Revealing Collision Geometry
    Normal Render geometry can accidentally hide Colliders, like a plane MeshCollider below a floor. By picking the “Force Overdraw” rendering mode the visualization will draw the Colliders on top of the Render geometry.



    Profiling
    With a few clicks common performance issues can be easily spotted.

    Active Rigidbodies
    The visualization can be made into a physics collision profiler by hiding Static Colliders and Sleeping Bodies. The result is that only the expensive simulated Rigidbodies are shown.




    MeshColliders with concave (triangle) meshes
    The concave (triangle based) MeshColliders tend to generate the most contacts when Rigidbodies are very near a collision with another Rigidbody or a Collider.

    You can visualize the concave MeshColliders by switching the Workflow to “Show Selected Items” mode, pressing “Show None” and selecting “Show MeshColliders (concave)”.




    What Else Is Coming?
    • A port for Unity 5.4.
    • Visualize raycasts.
    • Visualize contact points.
    • Visualize joints.
    • Show possible collisions only from current Colliders point of view.
    • Show what callbacks will be sent to colliders and triggers based on their current settings.
    • Nicer shading.
    • Timeline recording and scrubbing.
    • Network support.

    Scripting API

    (Real script reference has proper documentation)
    Code (csharp):
    1. namespace UnityEditor
    2. {
    3. class PhysicsVisualizationSettings
    4. {
    5.    enum FilterWorkflow
    6.    {
    7.      HideSelectedItems = 0,
    8.      ShowSelectedItems = 1,
    9.    }
    10.  
    11.    enum MeshColliderType
    12.    {
    13.      Convex = 0,
    14.      NonConvex = 1,
    15.    }
    16.  
    17.    static void InitDebugDraw () ;
    18.    static void DeinitDebugDraw () ;
    19.    static void Reset () ;
    20.  
    21.    static bool GetShowStaticColliders (FilterWorkflow filterWorkflow) ;
    22.    static void SetShowStaticColliders (FilterWorkflow filterWorkflow, bool show) ;
    23.  
    24.    static bool GetShowTriggers (FilterWorkflow filterWorkflow) ;
    25.    static void SetShowTriggers (FilterWorkflow filterWorkflow, bool show) ;
    26.  
    27.    static bool GetShowRigidbodies (FilterWorkflow filterWorkflow) ;
    28.    static void SetShowRigidbodies (FilterWorkflow filterWorkflow, bool show) ;
    29.  
    30.    static bool GetShowKinematicBodies (FilterWorkflow filterWorkflow) ;
    31.    static void SetShowKinematicBodies (FilterWorkflow filterWorkflow, bool show) ;
    32.  
    33.    static bool GetShowSleepingBodies (FilterWorkflow filterWorkflow) ;
    34.    static void SetShowSleepingBodies (FilterWorkflow filterWorkflow, bool show) ;
    35.  
    36.    static bool GetShowCollisionLayer (FilterWorkflow filterWorkflow, int layer) ;
    37.    static void SetShowCollisionLayer (FilterWorkflow filterWorkflow, int layer, bool show);
    38.  
    39.    static int GetShowCollisionLayerMask (FilterWorkflow filterWorkflow) ;
    40.    static void SetShowCollisionLayerMask (FilterWorkflow filterWorkflow, int mask) ;
    41.  
    42.    static bool GetShowBoxColliders (FilterWorkflow filterWorkflow) ;
    43.    static void SetShowBoxColliders (FilterWorkflow filterWorkflow, bool show) ;
    44.  
    45.    static bool GetShowSphereColliders (FilterWorkflow filterWorkflow) ;
    46.    static void SetShowSphereColliders (FilterWorkflow filterWorkflow, bool show) ;
    47.  
    48.    static bool GetShowCapsuleColliders (FilterWorkflow filterWorkflow) ;
    49.    static void SetShowCapsuleColliders (FilterWorkflow filterWorkflow, bool show) ;
    50.  
    51.    static bool GetShowMeshColliders (FilterWorkflow filterWorkflow, MeshColliderType colliderType) ;
    52.    static void SetShowMeshColliders (FilterWorkflow filterWorkflow, MeshColliderType colliderType, bool show) ;
    53.  
    54.    static bool GetShowTerrainColliders (FilterWorkflow filterWorkflow) ;
    55.    static void SetShowTerrainColliders (FilterWorkflow filterWorkflow, bool show) ;
    56.  
    57.    static FilterWorkflow filterWorkflow {  get; set; }
    58.  
    59.    static bool showCollisionGeometry { get; set; }
    60.  
    61.    static bool enableMouseSelect { get; set; }
    62.  
    63.    static bool useSceneCam { get; set; }
    64.  
    65.    static float viewDistance { get; set; }
    66.  
    67.    static int terrainTilesMax { get; set; }
    68.  
    69.    static bool forceOverdraw { get; set; }
    70.  
    71.    static Color staticColor { get; set; }
    72.  
    73.    static Color rigidbodyColor { get; set; }
    74.  
    75.    static Color kinematicColor { get; set; }
    76.  
    77.    static Color triggerColor { get; set; }
    78.  
    79.    static Color sleepingBodyColor { get; set; }
    80.  
    81.    static float baseAlpha { get; set; }
    82.  
    83.    static float colorVariance { get; set; }
    84.  
    85.    static float dotAlpha { get; set; }
    86.  
    87.    static bool forceDot { get; set; }
    88.  
    89.    static void UpdateMouseHighlight (Vector2 pos);
    90.  
    91.    static void ClearMouseHighlight () ;
    92.  
    93.    static bool HasMouseHighlight () ;
    94.  
    95. } // PhysicsVisualizationSettings
    96. } // UnityEditor
    97.  
    Update History
    2016-12-07
    • Update to Unity 5.5.0f3.
    • UI overhaul. Toolbar introduced. Filtering foldout removed. Things got smaller.
    • Fixed a bug in the Layer masking code.
    • Green is now used for Static Colliders and red for Rigidbodies.
    • “Non-convex” change to “concave”.
    2017-01-02
    • Update to Unity 5.5.1p1.
     
    Last edited: Feb 1, 2017
    Gamdiiii, justLC, AlanMattano and 4 others like this.
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,495
    I still think that using green for static colliders and red to rigidbodies makes much more visual sense and feels more consistent with the collider / physics colors we all are used to see in Unity.

    To me, this color scheme feels more intuitive as a long-standing user/developer of Unity Physics:

    Green: static colliders
    Red: rigidbodies
    Light-red: sleeping rigidbodies.

    upload_2016-11-26_18-46-57.png

    It's just my opinion, of course, I wonder what other users think.

    Anyways, the tool works great! A really good addition.
     
  3. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    I agree with green for statics and red for rigidbodies (and blue for kinematic)

    The only problem I see is that red/light red difference isn't visible enough. Maybe make sleeping rigidbodies yellow and make triggers white or gray?
     
    AlanMattano likes this.
  4. Adam-Mechtley

    Adam-Mechtley

    Administrator

    Joined:
    Feb 5, 2007
    Posts:
    290
    Hi! The problem is that is not very friendly to colorblind users.

    Untitled-1.png We should probably start from a palette like this one:
     
  5. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,495
    My suggestion is just about exchanging the color settings among Static Colliders and Rigidbodies. It uses same exact colors as in the default settings. If the default settings aren't an issue, I can't understand why my suggestions is...
     
    Prodigga likes this.
  6. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    Hi, thanks for the feedback :)

    I don't like using whites or greys because they're usually used by the default UI or default materials.

    I'm open to switching to green for static colliders + red for rigidbodies.
    But in the end the default is just a suggestion and will never be optimal for everyone. What about I provide some kind of OnPostReset event that allows users to override with their own default colors?

    Regards,
    Morten
     
  7. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,495
    As long as the colors are customizable in the inspector as they're now, I don't see any need of further events or coding. My suggestion is just exchanging the red-green colors in the default settings for providing more overall coherence by default, but anyone can actually set their preferences easily.
     
    laurentlavigne likes this.
  8. Skjalg

    Skjalg

    Joined:
    May 25, 2009
    Posts:
    211
    Why are they in the inspector and not in the Preferences with all the other colors? upload_2016-11-30_14-9-18.png
     
  9. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    they are not in the Inspector, they are in the Physics Debug window itself. I guess the reason for not putting them in the colors section is that the coloring is very domain specific.
     
  10. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    Hi All.

    I've updated the build:
    • Update to Unity 5.5.0f3.
    • UI overhaul. Toolbar introduced. Filtering foldout removed. Things got smaller.
    • Fixed a bug in the Layer masking code.
    • Green is now used for Static Colliders and red for Rigidbodies.
    • “Non-convex” change to “concave”
    Please post any feedback :)
     
    Edy, TheWarper and pvloon like this.
  11. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    416
    Will this tool work with current Unity release 5.5.1.

    Thanks
    Allan
     
  12. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    I can take a look at porting to 5.5.1
     
    laurentlavigne likes this.
  13. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
  14. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,495
    Thanks for the update! Now downloading...
     
  15. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    Looks really fun.

    Is this available for 5.6?

    Thanks,
     
  16. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    yes, it's built in.
     
  17. MaxLouis

    MaxLouis

    Joined:
    Dec 9, 2016
    Posts:
    1
    Is this working with 2D yet? If so I'm not sure why my rigidbodies are not showing?
     
    laurentlavigne and roointan like this.
  18. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,500
    Nice tool!!
    Can the Physics Debugger include a bool that fix the rendering frame rate to the physics fame rate?

    And also I could love complex visual physics handles for artist to be included in physics 3D!

     
  19. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,454
    This is super useful, it really helps a lot when trying to hunt down bugs and figure out why things are behaving weird.
     
  20. anthonov

    anthonov

    Joined:
    Sep 24, 2015
    Posts:
    160
    hi,
    When can we expect joint debuger/visualization ?
     
    xCyborg likes this.
  21. Ylisar

    Ylisar

    Joined:
    Jan 27, 2014
    Posts:
    18
    Any reason for developing this instead of adding like the 2 lines of code needed to enable physx visual debugger, which have all(?) of these features + a lot more. For example being able to record & frame by frame step a simulation, which would be a godsend.
     
  22. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,203
    When?
    (and 2D would be great too)
     
    roointan likes this.
  23. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Is there an ETA on a 5.4 port?
    Need this for a demo, but can't really move to anything higher than 5.4.3f1 (I've locked it in as my unity version until the project is complete)
     
  24. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    No because it's a feature. Features don't get backported. As a workaround make a copy of your project and upgrade it to use this I guess? Not perfect but I'm not sure what to suggest...
     
  25. BenSizerRovio

    BenSizerRovio

    Joined:
    Sep 25, 2017
    Posts:
    12
    When I single-step the frames in the editor, it looks like the 'normal' physics visualisation is moving each frame, but the physics debugger visualisation is not!

    physics-debugger.gif
    The object is set to Interpolate / Continuous Dynamic, if that's any help.
     
    laurentlavigne likes this.
  26. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,816
    Hi there! This is a great feature, I might be a bit late but if it's still being worked on, I was thinking it might be nice if there was an option to view surface normals on collider objects.
    Anyway, thanks!
    Pete
     
    yant and hippocoder like this.
  27. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,500
  28. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,816
    Wow I wasn't expecting that :eek:.
    That all sounds a bit sad.
     
  29. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    594
    There will be updates to the debug viz soon. We're looking into showing normals and contacts. This will happen after the PhysX 3.4.
     
    petey likes this.
  30. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Any chance on being able to visualize raycasts, sweeps and their hits in the future?
     
    hippocoder likes this.
  31. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    594
    Yes, showing queries is something that we should implement. That's a good idea, PVD has supported that since forever.
     
    zhuchun, Lars-Steenhoff and rz_0lento like this.
  32. roointan

    roointan

    Joined:
    Jan 8, 2018
    Posts:
    78
    No physics debugger for 2D?
     
  33. Alunze

    Alunze

    Joined:
    Jun 2, 2013
    Posts:
    11
    I humbly adhere myself to the petition for 2D physics debugger.

    Thanks!
     
  34. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,266
    There isn't a 2D physics debugger window no. There's some gizmo options in 2D physics settings though for showing contacts, AABB, colliders and colour options etc though.
     
  35. Leniaal

    Leniaal

    Joined:
    Nov 7, 2012
    Posts:
    119
    I have a problem where my terrain is sort of split up in small pieces and they look like artifacting pieces.

    Is this a known issue in anyway?

    https://imgur.com/a/HN024aA

    Edit: The imgur post got a bit messed up, only the first two are unique videos
     
    Last edited: May 16, 2019
  36. tomandjerry-tas

    tomandjerry-tas

    Joined:
    Feb 7, 2013
    Posts:
    22
    No physics debugger for 2D? joke , Unity 4.3 2d support ,new feacture , very very very very very very Slow
     
  37. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,266
    Not slow, not requested and a low priority. Enough 2D debug visualisations for most 2D devs. Rather than rant you could be constructive and explain what you actually want rather than simply want 2D and 3D to have exactly the same things. 3D doesn't have some things that 2D does and the same the other way around.
     
    akusep and hippocoder like this.
  38. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    594
    May I kindly ask to keep this thread communications professional please. Having all the other misconceptions discarded, the PhysX and Box2D integration support teams are actually surprisingly tiny, and may be reduced even further in the future as we see the new generation of tech emerge and mature. Plenty of great things were brought to you out of the good will and the energy of those few who get motivated by all the empowering comments here on forums, not out of some soulless bureaucratic central planning machine. Think motivation first when posting something that lets down.
     
  39. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    433
    Regarding showing queries, how about also providing an option for developers to visualize collision? It could be useful since most of the time we're dealing with "What it has hit" and "Why it didn't hit" :p
     
    John_Leorid and DrDigg0R like this.
  40. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Thank you for the awesome tool @MortenSkaaning @MelvMay @yant and others involved! ^^

    I checked the API and C bindings and sigh, it does not allow to set different colors for the different layers, unfortunately. It would be super helpful to be able to color colliders with different colors based on their layers, e.g. colliders on Walls layer with one color and colliders on Floor layer with another one, it would be super helpful for easier level design work.
     
  41. kai1010

    kai1010

    Joined:
    Aug 21, 2017
    Posts:
    1
    The physics debugger not works in Unity 2019.3 and later on my all three different Windows 10 PCs.
    It’s really killing me.
     
    Salvador-Romero likes this.
  42. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    645
    This is one of the best tools ever, thanks a lot for making it.

    How does it work? I wasn't able to find the drawing methods in the C# Reference of Unity - I want to write a visualisation tool to show which objects share the same material (to see where I can optimise draw calls). My firsts guess was that it's using Gizmos.DrawMesh but it has way better performance and more options, respecting depth and so on - is the source available anywhere? Can we somehow write our own visualisation tools based on this one?
     
  43. BigGameCompany

    BigGameCompany

    Joined:
    Sep 29, 2016
    Posts:
    109
    not working on the mac either.
     
    badman2000 likes this.
  44. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Additionally, is there some fundamental reason why Unity doesn't allow hooking up PVD into editor and development builds? Most game engines that use physx allow this.

    There's additional value of being able to playback the physics simulation afterwards. Unity already supports similar 3rd party debugging tool for Havok.
     
  45. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    I cant actually see anything when I try to use this, am I doing something silly? I get the physics debug window but where do I see the information it is meant to display?
     
    DonCornholio likes this.
  46. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    247
    Physics Debugger is great, but please, allow us to customize Color Choice.

    In my case I have huge scene with 100 000+ colliders, and need to asign correct Physical Materials to each. And color-coding would help a lot to find wrong assigned material
     
  47. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    594
    How do you see that customisation work for you? How do you configure colours?
     
    mitaywalle likes this.
  48. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    247
    May be we can have base class or interface

    Code (CSharp):
    1. public interface IPhysicsDebuggerColorSolver
    2. {
    3.    Color SolveColor(Collider collider);
    4. }
    Color is applied before transparency and randomization

    All inherited classes grabbed on Focus / OnEnable inside PhysicsDebugger window script.

    And there appear popup-selector with all available solvers

    Instance of selected IPhysicsDebuggerColorSolver itself is
    Code (CSharp):
    1. [SerializeReference] IPhysicsDebuggerColorSolver ColorSolver;
    And contains all settings, include colors to tweak

    I'll research, if I can edit source code of physics debugger myself, And try to make this realization, and share here.

    UPD: PhysicsDebugger has no opened source-code, and can't be embedded as package, so I can only wait for official recoloring system.

    If you have same problem with debugging / assigning PhysicaMaterial. You can adopt my PaintPhysicalTool from Github to your project
     
    Last edited: Jul 4, 2023
  49. yant

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    594
    Okie awesome, thanks for the suggestion. I think overall it does make perfect sense.
     
    mitaywalle likes this.
  50. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,203
    This thread still lives on.
    So there is no 2D physics debugger.
    Case for it: complex compositions
    upload_2024-3-4_19-33-44.png