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
  4. Dismiss Notice

meshrenderer.material.SetColor does not change color [LWRP]

Discussion in 'Scripting' started by U7Games, Nov 15, 2018.

  1. U7Games

    U7Games

    Joined:
    May 21, 2011
    Posts:
    943
    Hello..

    im trying to change an emission color from scripting by this way:

    Code (csharp):
    1.  
    2. [SerializeField]
    3. private MeshRenderer myPlayerRender;
    4.  
    5. private void Update(){
    6.         if (Input.KeyDown("z"))
    7.                 ChangeEmissionColor(Color.red);
    8.         if (Input.KeyDown("x"))
    9.                 ChangeEmissionColor(Color.blue);
    10.  
    11. }
    12.  
    13. private void ChangeEmissionColor (Color newColor){
    14.          myPlayerRender.material.EnableKeyword("_EMISSION");
    15.          myPlayerRender.material.SetColor("_EmissionColor", newColor);
    16. }
    17.  
    Maybe because LWRP ?
    There are somethings that are not working on LWRP yet, I'm not sure if this is the problem, or my code is not fine..
     
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    Realtime GI is not supported in LWRP according to this blog post: https://blogs.unity3d.com/2018/02/2...er-pipeline-optimizing-real-time-performance/

    I would think Emission would still work for the one material, and the lack of GI would mean the light from the emission wouldn't affect other objects. I can't find anymore reliable info. Maybe you can try to get it working with a different shader or with the default rendering pipeline as a test.

    Good luck!
     
    GubaLord likes this.
  3. U7Games

    U7Games

    Joined:
    May 21, 2011
    Posts:
    943
    Thanks for your answer..

    Yes, indeed, i have made a test with standard pipeline rendering, and works!, so i only can conclude that it is because LWRP WIP...
     
    GubaLord likes this.
  4. IAmChiagozie

    IAmChiagozie

    Joined:
    Jun 26, 2017
    Posts:
    23
    I have the same problem with lwrp:
    Code (CSharp):
    1. SetColor("_Color" Color.green);
    What's the shader name/nameID used in lwrp/Lit shader?
     
  5. SniperED007

    SniperED007

    Joined:
    Sep 29, 2013
    Posts:
    341
    Any fix for this yet for the LWRP?
    I have the same problem with:
    MeshRenderer.materials[0].color = color;
     
  6. mtarek2005

    mtarek2005

    Joined:
    Jul 22, 2017
    Posts:
    2
    they changed _Color to _BaseColor
     
  7. smallg2023

    smallg2023

    Joined:
    Sep 2, 2018
    Posts:
    102
    thanks :)
     
  8. leeeemk

    leeeemk

    Joined:
    Mar 12, 2020
    Posts:
    1
    this is the answer.
     
    Twilight1307 likes this.
  9. LoveraSantiago

    LoveraSantiago

    Joined:
    Nov 20, 2017
    Posts:
    18
    thanks