Hi, we’re making a debug view mode for physics collision geometry.
The idea is to enable the user to quickly inspect the collision geometry in their scene to decide whether collisions should, or should not, happen. This is usually an issue when the Render mesh and Collider mesh gets out of sync.
Scenes are often arranged by Collision Layer, so this tool allows you to quickly ignore layers to find out where the issues are.
The tool also enables the user to quickly select GameObjects that own the collision geometry, for further inspection or changes. This will be improved to select individual Collider components in the future.
The tool also enables the user to debug physics performance issues as it can highlight simulating Rigidbodies. This will have improved support in the future.
The build is based on Unity 5.3.4p4 so it should be stable for most users.
Limitations:
Cloth, Joints and WheelColliders are not supported yet.
Toggling Enable on a TerrainCollider many times causes random selection raycast failures.
When using multiple scene views, only the last scene view can effectively do picking.
Tree Colliders don’t highlight individual trees when hovering over terrains.
Drag-rectangle-to-select is not supported.
Q&A:
Q: Isn’t this like the PhysX Visual Debugger (PVD)?
A: It’s a light version of PVD with the advantage that we can select GameObjects and Assets directly inside Unity. Ease-of-use was our primary motivation for making the view mode. PVD can be tricky to work with because it is a separate application with different UI/UX conventions. PVD also has performance issues with large terrains.
Q: When will this be in a real Unity release?
A: Earliest in Unity 5.5, but I can probably supply you with custom per-version builds if you are interested. There is a good chance it can get backported as well.
Q: You made the drawings in mspaint, didn’t you?
A: Yes I did.
Future ideas:
User defined colors per Layer.
Show contact points
Improve curvature information by doing light-from-viewpoint shading, like in Maya.
Timeline recording and scrubbing.
Show more information, like Layer, when hover over a Collider.
Network support.
Expose more render control to user scripts.
C# API:
The name is expected to change from “PhysicsVisualizationSettings” to “Physics.DebugVis”.
Cannot be used without the Editor. Standalone players not supported.
public class PhysicsVisualizationSettings
{
public static void Reset ();
// properties
public static bool showCollisionGeometry;
public static bool enableMouseSelect;
public static bool useSceneCam;
public static float viewDistance;
public static int terrainTilesMax;
public static bool forceOverdraw;
public static bool showStaticColliders;
public static bool showTriggers;
public static bool showRigidbodies;
public static Color staticColor;
public static Color rigidbodyColor;
public static Color kinematicColor;
public static float baseAlpha; // (1 - transparency)
public static bool devOptions;
public static int dirtyCount;
public static bool GetShowCollisionLayer (int layer);
public static void SetShowCollisionLayer (int layer, bool show);
public static void UpdateMouseHighlight (Vector2 pos);
public static void ClearMouseHighlight ();
public static bool HasMouseHighlight ();
}
What does this object collide with? Potentially add a checkbox to the little scene view overlay to isolate the visualization to the current selection’s collision matrix. If I select an object in the scene (e.g., my character controller) then I would only see colliders on layers that will interact with the selected object’s collider.
What collision messages will be sent? Similar to previous point, but take into account presence/absence of a Rigidbody, kinematic/non-kinematic state. Potentially reveal a new checkbox in scene view overlay when “isolation mode” is enabled to further limit to only those objects that will send collision messages with the current selection.
Other default colors
Don’t use triangle/wire meshes to display colliders that are not triangle meshes or convex meshes. Make separate button for Convex Colliders.
Thanks for sharing, Morten! I think this will be a useful tool. It occurs to me that it could help provide information to help customers with some common problems/questions. For example:
What does this object collide with? Potentially add a checkbox to the little scene view overlay to isolate the visualization to the current selection’s collision matrix. If I select an object in the scene (e.g., my character controller) then I would only see colliders on layers that will interact with the selected object’s collider.
What collision messages will be sent? Similar to previous point, but take into account presence/absence of a Rigidbody, kinematic/non-kinematic state. Potentially reveal a new checkbox in scene view overlay when “isolation mode” is enabled to further limit to only those objects that will send collision messages with the current selection.
I’d suggest exchanging the Red and Green colors for the visualization. We all are used to see colliders and physics-related objects in green, and I’ve found that using green for static colliders (scenario) and red for simulating bodies makes a lot more visual sense. Check out the pic. The red simulating bodies get a better highlight in red over the green static scenario.
There is some problem when the colliders have some rotation wrt the rigidbody. The rigidibody in the picture (car) hasn’t any rotation, but the collider resides in a child gameobject with rotation X -90. The collider is rotated correctly (green wireframe at the car) but the PhysX visualization seems to be applying that rotation twice and the collider ends facing up.
Colliders that are far away from the camera position aren’t visualized in the PhysX view. Maybe there’s some cull by distance, so I’m not sure if this is the intended behavior. In the picture below you can see the large object at the upper left part of the view not getting the physx view. It also has a static collider.
Hope this helps! Let me know if I can help you further.
Edy
So I gave this a whirl on one of our levels and it seemed pretty good, which is nice. It let me see a few places where objects that should be sleeping aren’t sleeping which is what I was trying to track down (although just changing the wireframe colour is not super obvious, something more visible at a distance would be good).
Things I’d like to see:
Show contact points. The profiler shows we have a lot of contact points even on a supposedly ‘still’ scene. Would be good to see what’s actually happening here.
We drive lots of gameplay from physics callbacks, it would be good to see a representation of when these are firing and how often (usually we have custom code to explicitly ignore repeat events, but would like to see when / where this is happening as it’s wasted perf).
Lots of our non-sleeping objects seem to be due to hinges. Better visualisation of what hinges are up to would be great.
Looking forward to this being in a proper unity release! Thanks
We made a new forum for feedback on the Physics Debug Visualization for Unity 5.5.
Once Unity 5.5 is released I will update the build with the Physics Debug Visualization.
New features in the visualizer is filtering per Collider type and sleeping status. This enables the visualizer to function as an easy-to-use profiler.