[RELEASED] Physics Debug Extension

Nope, still won’t show up even with scene view hidden. I’ll try to test it out tomorrow with a fresh project to see if it’s some setting I’ve changed somewhere

EDIT: It does work in a new project. It seems like some setting or conflicting package is causing this, I’m in the process of narrowing it down.

Ok I think I figured it out. It seems like if I have any UI elements, it breaks the in-game rendering (so not directly related to any packages). Using OnGUI seems to break it completely, while using a UI element on a canvas seems to make all the debug shapes render super far away.
I have a pretty fragile workaround though:

  1. Don’t use SMAA on my camera
  2. Have some post-processing effect, such as bloom, enabled
  3. I add this to UnityGLDebug.cs: void OnRenderObject() => RenderLines(); (this seems to be needed even though I’m using URP with compatibility mode disabled)

Doing all of that still lets me render my UI and have the debug lines show up. It also seems that when using OnRenderObject, the lines are affected by post-processing effects (such as bloom or DOF) but without that (and with no UI elements rendering), the lines are not affected by post-processing.

Here is a minimal example project demonstrating all of this:
My project.zip (317.3 KB)

That’s an interesting bug that you found, I wonder what exactly might be happening with the combination of systems together. I will investigate this one before adding the patch. Would love to prevent having to call the draw lines that many times

I can confirm the replacement GLDebug script I provided is working in URP (Forward Renderer) Unity 6 without requiring PlayMode Gizmos enabled, post processing, or calling OnRenderObject.

I am using PreviewCondition.Both, 1f DrawDuration. (Lower draw durations work)

@amrahm If you are using the new GLDebug script, deleted the old dll + (restarted Unity), ensured the script is on your main camera, and still aren’t seeing the drawing, you can try replacing the shaders with these ones that are URP specific (although the originals work for me). Bear in mind if you use a the default draw duration it will only draw roughly every frame that it’s called.

@Rotary-Heart I like to make RotaryHeart.Lib.PhysicsExtension.DebugExtensions and it’s methods public so we can draw for debugging outside of Physics casts. This expands it’s uses massively.

GLlineZOff.shader (1.3 KB)
GLlineZOn.shader (1.3 KB)

I have not published an update with this fix since it seems there is still some issues to be fixed with this implementation. I can live with the issue of only having game view open to be able to see it, but there seems to be an issue with zdepth on URP that I have not yet been able to solve.

I have game and scene view side by side and it works. I may have noticed the zdepth thing when trying to correct the z-on shader, I can get it to work in the scene view but it’s affected by the camera angle/z-fighting in the game view. I can live without the depth but will investigate this.

@amrahm 's solution works for fixing Z by replacing OnCameraRender with void OnRenderObject() => RenderLines(); . My ZOn shader has ZWrite Off ZTest LEqual

Thanks for continuing to support this!

Are you sure it was limited to URP? I have unified the DrawLine and DrawRay methods to trim the fat in the DebugExtensions and noticed there were a few missing drawDepth flags on some of the Draw calls, and some accidental “Debug.” where “GLDebug.” were supposed to be.

I’ve also added DrawBounds, DrawArrow, and DrawCone

DebugExtensions.cs (34.8 KB)

Version 2.0 has been submitted to the asset store for review. This version includes:

  • Code cleanup and some minor performance gains
  • Fixes for URP thanks to @haywirephoenix and @amrahm for helping debug this
1 Like

Yes the issue is just in URP but as you said in the previous post, The solution posted by @amrahm does indeed work

1 Like

Great News! Version 2.0 is now live on the store!

@haywirephoenix I have made the debug class public and all it’s members so you can implement your own partial class for it and extend it with your own cone and any other debug methods you had.

1 Like

Legend, thanks for updating this. Can’t wait to try it.

In 2.0 I couldn’t get the lines to display in the Game view and found that the shaders weren’t being assigned. I modified the MaterialSetup method to grab the shaders before creating the materials and it’s all working great now in URP.

private void MaterialSetup()
{
    this.zOnShader = (this.zOnShader == null) ? Shader.Find("Debug/GLlineZOn") : this.zOnShader;
    this.zOffShader = (this.zOffShader == null) ? Shader.Find("Debug/GLlineZOff") : this.zOffShader;

    this.m_matZOn = (this.m_matZOn == null) ? new Material(this.zOnShader) : this.m_matZOn;
    this.m_matZOff = (this.m_matZOff == null) ? new Material(this.zOffShader) : this.m_matZOff;

    this.m_matZOn.hideFlags = (HideFlags)61;
    this.m_matZOn.shader.hideFlags = (HideFlags)61;
    this.m_matZOff.hideFlags = (HideFlags)61;
    this.m_matZOff.shader.hideFlags = (HideFlags)61;
}