# Render Custom Depth on Nanite enabled not working

**URL:** <https://forums.unrealengine.com/t/render-custom-depth-on-nanite-enabled-not-working/505390>\
**Category:** Rendering\
**Tags:** Post-Processing, custom-depth, unreal-engine, UE5-0, Nanite\
**Created:** [March 9, 2022, 4:25pm UTC](https://forums.unrealengine.com/t/render-custom-depth-on-nanite-enabled-not-working/505390 "2022-03-09T16:25:42Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![Czero\_69](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Czero\_69](https://forums.unrealengine.com/u/Czero_69)\
**Post date:** [January 19, 2023, 11:15pm UTC](https://forums.unrealengine.com/t/render-custom-depth-on-nanite-enabled-not-working/505390/21 "2023-01-19T23:15:18Z")

</div>

Ok guys,

This is now solved in ue5-main branch (upcoming 5.2). I can now write to stencil buffers from Nanite in the CitySample demo.

Thanks to [ZacD for pointing the correct commit](https://forums.unrealengine.com/t/5-1-nanite-not-able-to-write-to-stencil-buffers/746933/2) that solves the issue.

I have ended up with git checking out a little newer commit from ue5-main branch, namely `c825148dc6e0`.

Had to solve super minor issues when building ue5-main at this commit and running it with CitySample, but it seems it works fine for me now.

Not fully set up stencil values for my case, but here all buildings, trees, cars, are Nanite (except humans as skeletal meshes).

 ![00002](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/e/a/8ea5aefbf2be29b88232e769ad9e6764261333ee.png)

---

<div class="post-metadata">

**Author:** ![Vinayaka\_P](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Vinayaka\_P](https://forums.unrealengine.com/u/Vinayaka_P)\
**Post date:** [March 2, 2023, 7:08am UTC](https://forums.unrealengine.com/t/render-custom-depth-on-nanite-enabled-not-working/505390/22 "2023-03-02T07:08:56Z")

</div>

I’m waiting to test nanite stencils in upcoming ue5.2

---

<div class="post-metadata">

**Author:** ![NeoCrawler](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@NeoCrawler](https://forums.unrealengine.com/u/NeoCrawler)\
**Post date:** [March 28, 2023, 5:51pm UTC](https://forums.unrealengine.com/t/render-custom-depth-on-nanite-enabled-not-working/505390/23 "2023-03-28T17:51:28Z")

</div>

While Blueprints doesn’t allow you to change this parameter in runtime, C++ does. I ended up exposing a C++ function to Blueprints through the use of a “FunctionLibrary”.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/7/0/c70a1c7d8d3e1f44616637e87c3dbd0594f56de5.png)

My hightlight looks like this in blueprints. It does seem to work when I view the Nanite Visualization when hovering / unhovering.

**Header**

```auto
UFUNCTION(BlueprintCallable, Category = "Nanite")
static void SetDisallowNanite(UStaticMeshComponent* staticMeshComponent, bool disallow);

```

**CPP**

```auto
void UNCMethodExtensions::SetDisallowNanite(UStaticMeshComponent* staticMeshComponent, bool disallow)
{
	staticMeshComponent->bDisallowNanite = disallow;
}

```

**Result**  
 ![NaniteFix](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/b/5/4b58f22d85559e8759016d1a82fbbc0f459d29de.gif)

---

<div class="post-metadata">

**Author:** ![Levitikon217](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Levitikon217](https://forums.unrealengine.com/u/Levitikon217)\
**Post date:** [May 13, 2023, 1:52pm UTC](https://forums.unrealengine.com/t/render-custom-depth-on-nanite-enabled-not-working/505390/24 "2023-05-13T13:52:40Z")

</div>

This works great as a work around. Can’t wait for this to work naturally again one day.

---

<div class="post-metadata">

**Author:** ![Levitikon217](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Levitikon217](https://forums.unrealengine.com/u/Levitikon217)\
**Post date:** [November 2, 2023, 10:42am UTC](https://forums.unrealengine.com/t/render-custom-depth-on-nanite-enabled-not-working/505390/25 "2023-11-02T10:42:33Z")

</div>

This doesn’t seem necessary anymore in 5.3

[Previous page](https://forums.unrealengine.com/t/render-custom-depth-on-nanite-enabled-not-working/505390.md?page=1)
