Search Unity

Bug Changing parameter in custom function causes weird behavior in all material instances.

Discussion in 'Shader Graph' started by TheSky, Mar 11, 2023.

  1. TheSky

    TheSky

    Joined:
    Feb 16, 2015
    Posts:
    46
    I encountered a weird problem in a project.
    Basically, if you set a parameter in a custom shadergraph-function, it will affect all versions of that material in a weird way, even if you created seperate material-instances.
    I made a simple example to illutrate the problem.
    We have two objects in the scene. Both have the same material (image1).
    The shader does only one thing: reading a colour-parameter in a custom funtion and using this colour for the object. (image2)
    At Start, the c#-script on each object creates a new material instance.
    If i change the colour in one object per script (image3), you would expect, that only this one object changes it colour. Instead both colours change.
    Weirdly enough, if you set different colours for both objects, the colour of both objects are switching between these different colours, depending on the camera position. (Video1)
    I dont know what causes this behavior. It only happens, if you change the parameter inside a custom function.
    If you dont use a custom function, and instead use a parameter the regular way in shaper graph, and change this, everything works as expected. (image4)

    The Unity-Version is 2021.3.8f1.

    Image1:


    Image2:


    Image3:


    Video1:


    Image4:
     
    Last edited: Mar 11, 2023
  2. TheSky

    TheSky

    Joined:
    Feb 16, 2015
    Posts:
    46
    Am i really the only one, who encountered this?
    BTW, i checked with material.GetColor(), if both material-instances really have the correct colours. And they have. One always returns black, the other red.
    It seems the colour parameter inside the custom function is correctly being set.
    But i still have no explanation why both objects show the same colour, and why they switch the colour, when i move the camera.