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

how to set more than one material in the same object by scripts

Discussion in 'Scripting' started by elinbasol, Jul 1, 2015.

  1. elinbasol

    elinbasol

    Joined:
    Oct 9, 2014
    Posts:
    9
    hi guys, i have some problem, i have one object(game object), whit more than one material in the same skinne mesh render, my question is that is possible set more than 1 materials by script?, when i used Materials[index] = another material i get wrong, but when i used Materials[index] = new Material(another material);, i get the material base, si i get a white material, another way is material = another material, but is only work with the first materials y i cant set the anothers materials by scripts
     
  2. NintendoMaster00

    NintendoMaster00

    Joined:
    Jan 31, 2015
    Posts:
    86
    I am looking for the answer to this as well.
     
  3. elinbasol

    elinbasol

    Joined:
    Oct 9, 2014
    Posts:
    9
    i fix the problem creating another array of materials, and then i set the materials in the array, and final i set the object.materials = materials array
     
    WheresMommy likes this.
  4. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    Yep, @elinbasol is right. You cannot modify the material array directly. You have to "copy" it via script, change everything and put back the array like he did.