Physics Debug Visualization

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?
[quote]
Please remember to back up your projects before opening them in a custom build
[/quote]
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)

namespace UnityEditor
{
class PhysicsVisualizationSettings
{
   enum FilterWorkflow
   {
     HideSelectedItems = 0,
     ShowSelectedItems = 1,
   }

   enum MeshColliderType
   {
     Convex = 0,
     NonConvex = 1,
   }

   static void InitDebugDraw () ;
   static void DeinitDebugDraw () ;
   static void Reset () ;

   static bool GetShowStaticColliders (FilterWorkflow filterWorkflow) ;
   static void SetShowStaticColliders (FilterWorkflow filterWorkflow, bool show) ;

   static bool GetShowTriggers (FilterWorkflow filterWorkflow) ;
   static void SetShowTriggers (FilterWorkflow filterWorkflow, bool show) ;

   static bool GetShowRigidbodies (FilterWorkflow filterWorkflow) ;
   static void SetShowRigidbodies (FilterWorkflow filterWorkflow, bool show) ;

   static bool GetShowKinematicBodies (FilterWorkflow filterWorkflow) ;
   static void SetShowKinematicBodies (FilterWorkflow filterWorkflow, bool show) ;

   static bool GetShowSleepingBodies (FilterWorkflow filterWorkflow) ;
   static void SetShowSleepingBodies (FilterWorkflow filterWorkflow, bool show) ;

   static bool GetShowCollisionLayer (FilterWorkflow filterWorkflow, int layer) ;
   static void SetShowCollisionLayer (FilterWorkflow filterWorkflow, int layer, bool show);

   static int GetShowCollisionLayerMask (FilterWorkflow filterWorkflow) ;
   static void SetShowCollisionLayerMask (FilterWorkflow filterWorkflow, int mask) ;

   static bool GetShowBoxColliders (FilterWorkflow filterWorkflow) ;
   static void SetShowBoxColliders (FilterWorkflow filterWorkflow, bool show) ;

   static bool GetShowSphereColliders (FilterWorkflow filterWorkflow) ;
   static void SetShowSphereColliders (FilterWorkflow filterWorkflow, bool show) ;

   static bool GetShowCapsuleColliders (FilterWorkflow filterWorkflow) ;
   static void SetShowCapsuleColliders (FilterWorkflow filterWorkflow, bool show) ;

   static bool GetShowMeshColliders (FilterWorkflow filterWorkflow, MeshColliderType colliderType) ;
   static void SetShowMeshColliders (FilterWorkflow filterWorkflow, MeshColliderType colliderType, bool show) ;

   static bool GetShowTerrainColliders (FilterWorkflow filterWorkflow) ;
   static void SetShowTerrainColliders (FilterWorkflow filterWorkflow, bool show) ;

   static FilterWorkflow filterWorkflow {  get; set; }

   static bool showCollisionGeometry { get; set; }

   static bool enableMouseSelect { get; set; }

   static bool useSceneCam { get; set; }

   static float viewDistance { get; set; }

   static int terrainTilesMax { get; set; }

   static bool forceOverdraw { get; set; }

   static Color staticColor { get; set; }

   static Color rigidbodyColor { get; set; }

   static Color kinematicColor { get; set; }

   static Color triggerColor { get; set; }

   static Color sleepingBodyColor { get; set; }

   static float baseAlpha { get; set; }

   static float colorVariance { get; set; }

   static float dotAlpha { get; set; }

   static bool forceDot { get; set; }

   static void UpdateMouseHighlight (Vector2 pos);

   static void ClearMouseHighlight () ;

   static bool HasMouseHighlight () ;

} // PhysicsVisualizationSettings
} // UnityEditor

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.
8 Likes

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.

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

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

5 Likes

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?

1 Like

Hi! The problem is that is not very friendly to colorblind users.

We should probably start from a palette like this one:

4 Likes

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…

1 Like

Hi, thanks for the feedback :slight_smile:

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

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.

1 Like

Why are they in the inspector and not in the Preferences with all the other colors? 2868920--210171--upload_2016-11-30_14-9-18.png

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.

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 :slight_smile:

3 Likes

Will this tool work with current Unity release 5.5.1.

Thanks
Allan

I can take a look at porting to 5.5.1

1 Like

Update for 5.5.1p1 http://beta.unity3d.com/download/7bef31968871/public_download.html

1 Like

Thanks for the update! Now downloading…

Looks really fun.

Is this available for 5.6?

Thanks,

yes, it’s built in.

4 Likes

Is this working with 2D yet? If so I’m not sure why my rigidbodies are not showing?

2 Likes

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!

This is super useful, it really helps a lot when trying to hunt down bugs and figure out why things are behaving weird.

hi,
When can we expect joint debuger/visualization ?

1 Like