Search Unity

How to change color via Script on HDRP

Discussion in 'Scripting' started by DawgVinci, Aug 23, 2019.

  1. DawgVinci

    DawgVinci

    Joined:
    Feb 11, 2019
    Posts:
    8
    Hey Guys,

    this may sound like most noobish question, but i'm trying to change the color of a material via script (like Player hits a box, the color changes.
    All of my attempts failed and i really don't know what i'm doing wrong. So if anybody could help me out, i would really appreciate. I'm working with 2018.3.14f.

    Thanks
     
  2. iruizapo

    iruizapo

    Joined:
    Jul 7, 2017
    Posts:
    2
  3. konsic

    konsic

    Joined:
    Oct 19, 2015
    Posts:
    995
    How to access emission property?
     
  4. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
    @DawgVinci
    You can't use
    Material.color
    as this is a shortcut for
    Material.SetColor("_Color", ... )
    but in HDRP we use
    _BaseColor
    .
    So you need to use
    Material.SetColor("_BaseColor", ...)
    .

    @konsic
    Similarly, the emissive color is
    _EmissiveColor 
    .
    Note that we implemented some editor code do strip out the emission code in the shader if the color is full black (no emission) : this will cause the emission to not display if you change the value through script. To avoid that, you can simply have the emission not zero : (0,0,1/255) for example.
     
    TwoBeees and konsic like this.
  5. konsic

    konsic

    Joined:
    Oct 19, 2015
    Posts:
    995
    What is emissive intensity property name ?
     
  6. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
    _EmissiveIntensity
    (I suggest that you look in the material using the inspector in debug mode)
     
    konsic likes this.
  7. DawgVinci

    DawgVinci

    Joined:
    Feb 11, 2019
    Posts:
    8
    @Remy_Unity thanks, got it. Is it also possible to change the vertex color per collision?
     
  8. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
    @DawgVinci I'm not sure to get what you want to do here ...
     
  9. Minelaus

    Minelaus

    Joined:
    Dec 28, 2022
    Posts:
    1
    To keep this a little bit up to date , for the standard shader the HDR color name is now _EmissionColor .