Change GameObject Layer OnPreRender and OnPostRender not working?

Hi everyone,
One Skinnedmesh, Two cameras (one is Main Camera, the other is RenderTexture Camera), draw the scene, When RenderTexture camera begins, get the skinnedMesh to the layer of the RenderTexture camera and change its material too, this is supposed to draw the skinnedMesh to the camera’s renderTexture.

Sounds simple enough, but actually not. the RenderTexture camera always draw nothing. to simplify things, i tried to change the skinnedMesh’s layer and keep its material untouched, but still nothing happend. to make things even simpler i put just a box (no children) and change its layer still nothing.

What’s your suggestion? here is the code i do the chagne

//RTTCamera.cs
void OnPreRender()
{
   meshTarget.layer = camera.layer;
}

void OnPostRender()
{
    meshTarget.layer = 0; // restore its layer to default
}

thank you.

Very late response but for anyone else interested:

Use OnPreCull instead of OnPreRender

3 Likes