Search Unity

Change Transparency of Object with a Shared Material

Discussion in 'General Graphics' started by B_Rock_Shooter, Oct 16, 2017.

  1. B_Rock_Shooter

    B_Rock_Shooter

    Joined:
    Jun 10, 2014
    Posts:
    18
    So the coding is probably not hard I just can't find the right syntax.

    I have a material. When an object instantiates with this material I want just the new object to be translucent and not the other objects using the same material. So far, cant change just the new object, all the others change too as I seem to be changing the source material. For context think of the game Fortnite. You spawn a wall object, it is see through but when you place it, it becomes opaque. That is what I am trying to accomplish, only the newly spawn object is see through.
     
  2. ifurkend

    ifurkend

    Joined:
    Sep 4, 2012
    Posts:
    350
    Just create a new (opaque) material and switch to this new material from the original (transparent) material whenever you want.

    Edit: In case of material instancing which prevents batching, you should also prepare a mesh prefab which uses the final (opaque) material and instantiate the complete object once the transitioning animation is finish and destroy the transitioning object.
     
    Last edited: Oct 16, 2017
  3. B_Rock_Shooter

    B_Rock_Shooter

    Joined:
    Jun 10, 2014
    Posts:
    18
    OK, that was what I was going to originally do but didn't seem like it would scale very well. In this case, I only have 3 materials, so creating 3 more is no big deal. Just surprised Unity doesn't have a way of doing it that doesn't involve creating new mats.
     
  4. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276