Changing sprite renderer material cause sprite disappear

I created my own shader using shader graph to cover my specific problem. I need to create some kind of FOV for my main camera. Shader take global position of the camera and offset global position of mask on material assigned to multiple sprites. That let me insert few sprites on scene and mask will always be in same global position as camera.


That works just fine, and I am happy with the result, but…
Now I need to have couple of objects with this material always “visible”. I was trying a lot of ways to do this, but always something goes wrong. Whatever I tried it finished as sprite disappear.

  1. I was trying to use Branch node in shader graph to turn on and off mask, based on property changed by C# script (MaterialPropertyBlock) for single object. Sprite disappear whenever I want to switch its state.

  2. Next time I tried change radius property via C#, same problem, but if I am passing Camera.main.transform.localScale.x to this property it is OK, and i can adjust radius using camera scale.

  3. Finally, i was trying to just switch material on single object via script…disappear. It is disappearing even I manualy switch material on runtime.

There are two more things to say:

All this sprites are instantiate by some kind of generator, maybe problem is placed there, but it is just normal instantiate. I wrote small script to instantiate same prefab, and this one works fine. I can change material manualy and it works.

Second one, I find out that when I am changing material on sprite or properties, sprites wireframe is changing. If normal sprite is like two trinagles, that after change material it is disappear. Only if i select object, i can see rectangle outline around it.

I am going to go through my generator scripts tomorow, maybe i`ll find something, but it is looking weird.

Apologize my english, if something isn`t understandable i can try to give you more context.

I rebuild my generator to Instantiate every object from same place in code, and it seems to fix problem.