Render Custom Depth on Nanite enabled not working

Hey all! I noticed that when Nanite is enabled on a static mesh, using render custom depth will no longer work on that mesh… Is there a work around for this or a setting that I am missing?

The material I am using is a basic highlight/outline material I found while following a tutorial. I will look into the custom depth material and see if I can’t sort anything out, but if anyone has any other feed back, that would be awesome!


Looks like SceneTexture expressions cannot be used in opaque materials… and from what I’ve read is Nanite can only use opaque materials?.. this stinks :confused:

1 Like

I just found out the same thing. Bummer :frowning:

1 Like

I also just encountered this same problem.
Would love to know if anyone finds a workaround, or hears anything on the roadmap for adding this feature back in.

1 Like

I noticed this issue has been fixed in the 5.0 Release

Edit: My mistake. I had changed my configs and updated to 5.0. I was seeing the stencil draw and able to use it in my post process, and I assumed the issue had been fixed. However upon revisiting, it no longer worked. I believe that the nanite meshes were just not rendering with nanite. Likely due to some config I had been playing with.

1 Like

@BenVlodgi So, you have been able to make nanite meshes write into custom depth?

1 Like

Bumping this topic. @BenVlodgi Did you managed to get it working? If so how?

So far only non-nanite meshes are showing on my custom depth and stencil buffers.

I never read this was also a “feature” of nanite :S

1 Like

This is happening to me too, Render CustomDepth Pass doesn’t show with nanite activate on meshes… :cry:

Same here, very inconvenient that nanite meshes can’t use the customdepth pass.

Same here (UE5 release 5.0.2). It is interesting thou that the material-id is accessible when selected in the editor view mode. Here is my (ugly) workaround:

For all actors of interest:

  • copy a mesh that represents this actor
  • disable “Nanite Support” for the created mesh
  • optionally: Simplify it. Forex. lower the LOD of the created mesh (I use quite low-level as it is fine for just stencil mask, like LOD3 or ~6% of triangles)
  • add it to the actor root component
  • Make it non-occluding the original mesh. Naive idea would be scaling it to x,y,z=(0.99, 0.99, 0.99), but this results with some overlapping glitches anyway. See below for better solution [1].
  • disable “Render in Main Pass” (note: it still will be visible as black when it occludes something, that’s why we need to make it non-overlapping)
  • disable collisions: “Generate Overlap Events”, Collision Presets->NoCollision
  • enable “Render CustomDepth Pass”
  • set “CustomDepth Stencil Value”

here is a proof-of-concept. The segmentation mask in the middle is built upon a stencil buffer.

[1] ad non-overlapping. A better idea would be the “erosion” operation over the created mesh. For that, I exported a mesh and loaded it to MeshLab (free software). Here is how to achieve erosion effect in Meshlab: Is there a function to dilate/erode a mesh in meshlab? - Stack Overflow

To sum up, two approaches are:

A. Filter → “Remeshing, Simplification and Reconstruction” → Uniform mesh resampling and set negative offset.

B. Filter → “Smoothing, fairing, and Deformation” → “Per Vertex Geometric Function” and create a function that adds/subtracts the value of the normal to the coordinates of each vertex

x = x-0.3*nx
y = y-0.3*ny
z = z-0.3*nz
1 Like


Here is how to make it invisible in the scene (and invisible in the depth buffer and other buffers like normals, velocity, …) and visible in the stencil buffer only.
For a copied new mesh with disabled nanite:

  • disable “Render in Main Pass”
  • disable “Render in Depth Pass”
  • enable “Render CustomDepth Pass”
  • set Stencil Value to some int

Just in case anyone is still looking into this topic - I have read an official document (Nanite Virtualized Geometry in Unreal Engine | Unreal Engine 5.0 Documentation) mentioning that nanite doesn’t support custom depth or stencil. I am wondering at this point if nanite will support custom depth or stencil in the future.

Edit - I have found this ticket (Unreal Engine Issues and Bug Tracker (UE-149878)). I am not sure if it’s related, but it might be worth sharing here.


UE-149879 (Unreal Engine Issues and Bug Tracker (UE-149878)) is updated to be fixed in UE5.1. Since I was playing with UE5.1 Preview 1, I tested displaying custom stencil on nanite-enabled static meshes. I can see that the custom stencil is displayed like a charm! While I don’t think we know the exact timing of UE5.1 release, we now know that it’s a solved problem. :slight_smile:

Are you sure about this? I just tried it and stencil/custom depth are still not showing on Nanite meshes. Make sure your project has SM6 on, it’s possible you enabled Nanite but it’s not actually ‘on’.

Thanks for the note. I wasn’t aware of the SM6 setting relevance, and I turned it on in my project. UE5.1 Preview 1 showed at least what I was waiting for, so I would like to share the configurations that I tried.

  1. I created a new project using a template from UE 5.1 Preview 1. I used the Vehicle template. There is no specific reason though.

  2. I changed two project settings: SM6 and Custom Depth-Stencil Pass

  1. I placed a static mesh from Content Browser. The static mesh that I picked up didn’t have nanite enabled, so I enabled it. Then, I changed two settings of the instantiated static mesh by choosing it from the viewport: enabling Render CustomDepth Pass and giving 2 (arbitrary number) to CustomDepth Stencil Value

  1. Finally, I applied CustomStencil to Post-Process Materials in PostProcessVolume. The viewport showed the CustomStencil value and the static mesh has nanite on.

When I did the same steps in UE5.0.3, the custom stencil wasn’t displayed. Having said that, this is a preview supposed to be unstable, and the configuration space of Unreal Engine is huge in general. So, I am not confident that what I did here is directly relevant to what you are looking for. I hope this posting still helps though.

1 Like

Hey I tested it again, it definitely doesn’t work with Nanite unfortunately. You need the target RHI to also be set to DX12 for Nanite to work, to check that Nanite is working see if it will show the Nanite overview in the view modes. I guess that the reason it -appears- to be working for you is because your RHI is defaulting to DX11 and thus Nanite isn’t actually enabled in the first place.


I’ve just tested it with UE5.1 but my stencils are still not working with nanit meshes.

1 Like

To summarize this issue:

  • It doesn’t actually work in 5.1, it only worked because of incorrect settings (?)

  • I have it set RHI to DirectX12 + Nanite enabled + Custom Stencils, and I can’t get it to work on the latest official 5.1 release (as @Razdraz/@LucenDev also mentions)

  • It seems like that issue mentioned earlier is related to text outlines in the UI since it is filed under [UE - Editor - UI Systems] and the commits affect Slate related code

So we need a bug report on this, I think!

I can’t seem to find another issue on the Bug Tracker. I will try to submit a new one later today.

Update 1: I submitted a bug report just now.

Update 2: Nevermind, I browsed the docs just now to double-check and it’s been there all along – it clearly says that it isn’t supported:


Update 3: FWIW, Epic created a bug report for it here: Unreal Engine Issues and Bug Tracker (UE-171655)


It works in 5.1 Release and UE5.1 not support DX11 any more.

Nanite mesh does not support Custom Stencils,but its proxy mesh and the normal static mesh supports it. In some platform that not support Nanite or use disallow Nanite,The Nanite mesh will be convert to normal mesh or proxy mesh.

If it doesn’t work well,the bug is the disallow Nanite function.

The doc describes the situation in Hybrid Non-Nanite and Nanite Content Workflows chapter.

Hello guys,

What is the current status?

As I understand, the 5.1 docs says it is not (yet) supported

Nanite-enabled meshes do not currently support:

  • Custom depth or stencil

If so, why these tickets says it’s fixed/resolved?

possibly related issue (however this one does not mention ‘Nanite’):

I would really have a great usage of writing to stencil buffers globally for entire CitySample demo full of nanite meshes. Copying mesh (and making it no-nanite), using Nanite Pass Switch seems to be a workaround applicable manually only to some small portion of selected actors, but it seems it is not a good way to go globally with a huge scene like that. My usecase is creating a segmentation masks, where I can controll segmentation classes by simple regexes (classes like: pedestrain, car, building, road, sky, traffic_sign etc.).

Any chance we get this feature implemented in 5.2? Or maybe to get more insights of what needs to be done to make Nanite working with stencils buffer writing. Maybe it is quite easy or moderate difficulty task - so it can be pushed by the community?