Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  5. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    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
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,251
    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.
     
    AlanMattano and laurentlavigne like this.
  3. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    906
    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

    Unity Technologies

    Joined:
    Feb 5, 2007
    Posts:
    170
    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:
    1,251
    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:
    1,251
    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:
    109
    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:
    385
    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:
    1,251
    Thanks for the update! Now downloading...
     
  15. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    282
    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?
     
  18. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    905
    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:
    6,180
    This is super useful, it really helps a lot when trying to hunt down bugs and figure out why things are behaving weird.
     
  20. bsmall

    bsmall

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

    Ylisar

    Joined:
    Jan 27, 2014
    Posts:
    7
    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:
    2,013
    When?
    (and 2D would be great too)
     
  23. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,868
    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 Moderator

    Joined:
    Apr 11, 2010
    Posts:
    23,776
    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,207
    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:
    905
  28. petey

    petey

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

    yant

    Unity Technologies

    Joined:
    Jul 24, 2013
    Posts:
    203
    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. rizu

    rizu

    Joined:
    Oct 8, 2013
    Posts:
    580
    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:
    203
    Yes, showing queries is something that we should implement. That's a good idea, PVD has supported that since forever.
     
    rizu likes this.