Search Unity

Accessing Material by name from Renderer

Discussion in 'Editor & General Support' started by littlelingo, Dec 22, 2006.

  1. littlelingo

    littlelingo

    Joined:
    Jul 18, 2006
    Posts:
    372
    Hiya,

    I have a GO which has mutliple materials assigned to it. I would like to access these materials by name without iterating through sharedMaterials. Does anyone know if this could be done and how?

    Thanks for the help!

    -- Clint
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    You have to iterate through them if you want to find it by name.
     
  3. littlelingo

    littlelingo

    Joined:
    Jul 18, 2006
    Posts:
    372
    Okay... Great thanks Jo!

    Regards,

    -- Clint
     
  4. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Of course you don't have to do this everywhere. Just write yourself a helper function that given a Renderer and material's name will find and return the needed one, or return null if none found.
     
  5. littlelingo

    littlelingo

    Joined:
    Jul 18, 2006
    Posts:
    372
    Good thought Aras!

    My concern is iterating through this list will have some impact on performance as I am currently not sure how often a change to a material will be required.

    Thanks!

    -- Clint
     
  6. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Come on, do you have hundreds of materials per object and want to find them thousands of times per frame? I guess not.