Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Why GameObject (cube) keeps getting shader from another scene and vice - versa?

Discussion in 'Scripting' started by Exnihilon, Sep 9, 2014.

  1. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Hello to all. I came across a weird behavior in Unity Editor. I have a cube in one scene (scene1) with a material (mat1) and a Mobile/Vertex Colored shader. Another cube in a second scene (scene2) with same material has to be shaded with FX/Flare.

    Problem is that, this shader keeps changing to FX/Flare, or Mobile/Vertex Colored without wanted to be like that. It is happening in an automatic way, as I cannot be having the same material with different shaders in different scenes?

    Tried to make one cube in scene1 a prefab, but as I get from scene2 back to scene1, cube on scene1 gets the shader of scene2, and vice versa. Any clues on how to solve this issue, will be appreciated.
     
  2. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    A material is basically a shader with some values (float, texture, color) to go along with it.

    If you need another shader, you need to make another material.
     
  3. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Hello @Garth Smith. Thanks for the tip. Being a newbie, how to make a new material with shader? I choose material, then a shader and applied them on a gameObject? Then should I save or something in the editor?
     
  4. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Well I made a copy of mat1, attached the shader of scene1 and did the same for mat1 with the other shader in scene2. I was mistaken that Unity3d treats each scene as being an isolated "game environment", so I could have each object in each scene with the same materials.
    It was wrong in my case. Now all works fine, case closed. Thanks @Garth Smith for pointing me to the right direction.
     
    GarthSmith likes this.