How to reduce visibility of instanced meshes separately as they get near to camera?

Hi. I’m developing an endless running game and I want to fade obstacles when they take place between camera and player and reduce their visibility as they get near to camera. All my obstacles are instanced meshes which are parented by another mesh for controlling transform of the obstacle. I tried to change the visibility of the parent mesh, but that didn’t work. I tried to use instancedBuffer.color it worked but only for the first render and after that changing it didn’t work. Any solution?

We need a small repro in the playground without the full game. This would help a lot.