CustomDepthStencilValue cannot be changed while custom depth is on

So I added Tom Looman’s Multi-color Outline Post Process to my project. It works great, except I believe I’ve found a bug with the CustomDepthStencilValue.

I have set up an actor to use the outline post process in C++. When I spawn it into the world I set SetRenderCustomDepth(true) on its mesh. Later on as the gameplay dictates, I set its CustomDepthStencilValue to represent different states of the actor, so it is outlined in different colors. The problem is that no outline appears. The post process doesn’t kick in.

Upon inspecting the actor in the Details panel during play, I can see the actor’s mesh has Custom Depth ticked and I can see the CustomDepthStencilValue changing as the game plays, but there is no outline effect.

Eventually, I discovered that changes to CustomDepthStencilValue don’t appear to have any effect unless Custom Depth is turned off and back on first. This seems to give the engine a kick and get it to take notice of the change to the CustomDepthStencilValue.

For example, this fails, i.e. no outline appears on the actor.

Mesh->SetRenderCustomDepth(true);
Mesh->CustomDepthStencilValue = 254;

Whereas, this works, i.e. an outline appears on the actor.

Mesh->SetRenderCustomDepth(false);
Mesh->SetRenderCustomDepth(true);
Mesh->CustomDepthStencilValue = 254;

for unreal 4.17 i found a workaround for it:

Mesh->SetRenderCustomDepth(true);

Mesh->CustomDepthStencilValue = 254;

//refresh object on CustomDepth

Mesh->SetVisibility(false);

Mesh->SetVisibility(true);

Thanks bro, it worked for me!

yeah took me a while to work this out and i came to the same conclusion, such a dirty hack.