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

runtime changing detail albedo map

Discussion in 'Editor & General Support' started by yoonity, Jun 20, 2015.

  1. yoonity

    yoonity

    Joined:
    Nov 9, 2014
    Posts:
    7
    Hi. I have seen this question before but not found an answer. I am trying to change the detail albedo map in runtime for the standard shader material. While I can change it ok, the object doesn't show it in the scene or game window unless I expand the material in the inspector. When I do this, it is fine in all windows. Is there something I'm missing?
     
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    I think you might be modifying the shared material. If you modify the object own material (using MeshRenderer.material) the changes will happen immediately and only to the one object (and not others of the same material).

    I don't know if this is the cause of your problem though. Best of luck!
     
  3. Sinya

    Sinya

    Joined:
    Jun 9, 2015
    Posts:
    1
    same problem. looking for solution
     
  4. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,986
  5. inewland

    inewland

    Joined:
    Dec 6, 2012
    Posts:
    20
    You need to enable keywords for each map you update at runtime. For Detail Albedo you need to add:

    Code (CSharp):
    1. myRenderer.material.EnableKeyword("_DETAIL_MULX2");
    2. myRenderer.material.SetTexture("_DetailAlbedoMap", MyTexture);
     
  6. danmartelly_caliper

    danmartelly_caliper

    Joined:
    Jul 11, 2016
    Posts:
    3
    This thread helped me 1.5 years later on Unity 5.6.03f3. Thanks inewland! You had the solution that worked.

    I had the same symptoms described by yoonity where the detail texture would only show up when the material component was expanded.
     
  7. EricJ13

    EricJ13

    Joined:
    Feb 28, 2009
    Posts:
    354
    Two years later this helped me too. I was erroneously trying


    Code (CSharp):
    1.     myRenderer.material.EnableKeyword("_DetailAlbedoMap");
    2.     myRenderer.material.SetTexture("_DetailAlbedoMap", MyTexture);
     
  8. wenderRondonia

    wenderRondonia

    Joined:
    Mar 15, 2015
    Posts:
    29
  9. AdhikS

    AdhikS

    Joined:
    Dec 5, 2016
    Posts:
    5
    material.EnableKeyword() is not helping me...Plzz check my code
    go.GetComponent<MeshRenderer>().materials[k].EnableKeyword("_DETAIL_MULX2");
    go.GetComponent<MeshRenderer>().materials[k].SetTexture("_DetailAlbedoMap", aoTexture);
    I am downloading materials via one Assetbundle and AOMap via second and then i am applying..
    the detail texture would only show up when the material component was expanded.
     
  10. tidytibs

    tidytibs

    Joined:
    Nov 17, 2016
    Posts:
    1
    7 Years later this helped me, too.