Search Unity

Multiple Material Single Objects

Discussion in 'Scripting' started by HellSinker, May 15, 2016.

  1. HellSinker

    HellSinker

    Joined:
    Apr 18, 2013
    Posts:
    65
    Before I even ask; I'd just like to say I don't care how technical this gets, I'm more after a solution that works.

    Is it possible in anyway to apply multiple materials to a single mesh?

    In detail; I am trying to create a dynamically allocated mesh and apply a few materials to it; to date my knowledge in this area has led me to presume that I would need a texture atlas. In my current situation, this is undesirable, simply because several textures have detail maps which are nigh on imposible to atlas correctly - if no other answer is forth coming; I will probably go with this option, and make a shader that can handle it somehow.

    Thanks in advance for any consideration in this problem.
     
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Isn't there a material array or something in mesh renderer?
     
  3. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    Meshes take a array of materials, these link up to material ID of a imported mesh. In your case of using a procedural mesh, you will have to Mesh.subMeshCount and Mesh.SetTriangles more or less just set the subMesh count to the amount of materials you need, and when you do your setTriangles while constructing your procedural mesh you need to use the proper int in the submesh param.

    the id you use in the submesh parm relates to the ID to use in the materials array
     
  4. HellSinker

    HellSinker

    Joined:
    Apr 18, 2013
    Posts:
    65
    thankyou muchly :) I will look into this.