Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Same material, different shader per object - URP

Discussion in 'Universal Render Pipeline' started by Deornoth, Jul 20, 2022.

  1. Deornoth

    Deornoth

    Joined:
    Oct 8, 2021
    Posts:
    10
    Hello,

    I've created a selection shader to highlight objects that the player can interact with (I use a Fresnel effect etc.)

    Currently, I have a script that generates copies of all materials, but changes the shader to this selection shader.

    Then, when I want an object to appear selected, I change its material... then change it back again when it is deselected.

    This seems very clunky. I feel that it would be much cleaner solution would be some way to override just the shader instead of the whole material.

    Is this possible? - If not, any other suggestions on how to do this, or is my current approach as good as it gets?
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,971
    You can do material.shader
     
  3. Deornoth

    Deornoth

    Joined:
    Oct 8, 2021
    Posts:
    10
    No, materials are shared by many objects.
     
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,971
    Then reference the old and new material and switch between those