Graphics.RenderMesh doesn't work in URP

What the title says. Graphics.RenderMesh does absolutely nothing in URP/HDRP, however it works fine in the Built-in pipeline.

Graphics.DrawMesh however, seems to work fine in all pipelines.

Unity 2021.3.4f1, URP 12.1.7. Has anyone encountered this?

I think I found the culprit, here’s the solution for those that hit the same pitfall:

The default values for the RenderParams struct (that Graphics.RenderMesh takes as input) work for the built-in pipeline but don’t work at all for SRPs.

If you create a RenderParams instance using its constructor, the value of RenderParams.renderingLayerMask is initialized to a value other than 0. However if you create a RenderParams instance using the default constructor (which uses the default value of each type to initialize the struct’s members), renderingLayerMask gets the default value for unsigned ints (zero) so bitwise ‘&’ with any layer will always yield 0, ensuring nothing gets rendered.

So what if you want to create a RenderParams struct without passing a material to its constructor? then you need to explicitly set the value of renderingLayerMask to GraphicsSettings.defaultRenderingLayerMask, otherwise RenderMesh won’t render anything.

I’m reporting this as a bug since:

  • It behaves differently depending on the render pipeline being used.
  • The default values don’t work at all in SRPs, it stands to reason than assigning a mesh and a material should be all that’s necessary for this to work.
  • The need for using a specific constructor or populate the struct yourself with values other than the defaults isn’t mentioned anywhere in the documentation for either RenderMesh or RenderParams, should at least be mentioned in RenderParam’s constructor whose only documentation as of writing this is “Constructor.” - duh.

Stumbled upon the solution by mere chance, was ready to mark “RenderMesh” as broken and move on to DrawMesh instead.

Okay, I was going to tell you “thank you ever so much because I ran into this exact issue with an asset I’m using” … but you would know, because you are developing the asset. Anyway, enjoy my emails pointing you to your own post :smile:

This fixed my problem specifically the “renderingLayerMask = GraphicsSettings.defaultRenderingLayerMask”. Thank you very much and I hope you have a nice day! :slight_smile: