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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Android Material Error !

Discussion in 'Android' started by Mhmud-Fadel, Feb 4, 2016.

  1. Mhmud-Fadel

    Mhmud-Fadel

    Joined:
    Nov 13, 2013
    Posts:
    41
    Hi :)
    I'll start with a screenshot:
    render_error.jpg

    I'll explain my problem, I make a scene with Unity 5.3, this scene contains a Cornell Box, the simple idea is when I touch the power icon, the light switched from On to Off " all lights is baked in 3ds max + VRay " So I used here switch from Unlit/Texture shader to Mobile/Diffuse shader to looks that lights are off
    in Unity editor all done well, but in Samsung Android the Shader looks one color like missing materials

    Here is my button power code:
    Code (JavaScript):
    1. var spriteOff : Sprite;
    2. var spriteOn : Sprite;
    3.  
    4. var shader1 : Shader;
    5. var shader2 : Shader;
    6.  
    7. var parent : GameObject;
    8.  
    9. function Update()
    10. {
    11.       shader1 = Shader.Find("Mobile/Diffuse");
    12.      shader2 = Shader.Find("Unlit/Texture");
    13. }
    14.    
    15. function OnMouseDown()
    16. {
    17.  
    18. var renderers:Renderer[] = parent.GetComponentsInChildren.<Renderer>() as Renderer[];
    19. for (var child : Renderer in renderers )
    20.      {
    21.         if (child.material.shader == shader1)
    22.             child.material.shader = shader2;
    23.         else
    24.             child.material.shader = shader1;
    25.      }
    26. if(GetComponent(SpriteRenderer).sprite == spriteOn)
    27.     GetComponent(SpriteRenderer).sprite = spriteOff;
    28.     else
    29.     GetComponent(SpriteRenderer).sprite = spriteOn;
    30.  
    31. }
    32.  
    How can I solve that ?
     
  2. Mhmud-Fadel

    Mhmud-Fadel

    Joined:
    Nov 13, 2013
    Posts:
    41
    no answer !
     
  3. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,121
    As per the documentation here:

    Sounds like the cause. To fix it, make sure you have a hard reference to the shader - instead of using 'Shader.Find', you should 'connect' the correct shaders to shader1 and shader2 in the inspector! This way, Unity will know for sure that you want that shader included in your project.

    When you use Shader.Find, Unity can't guess which shaders you want to include in your game (because you can pass any string in to Shader.Find. So Unity ends up excluding any shader in your project that isn't directly referenced by any object.
     
  4. Mhmud-Fadel

    Mhmud-Fadel

    Joined:
    Nov 13, 2013
    Posts:
    41
    Great Explain :) Thanks Prodigga
     
    Prodigga likes this.