Search Unity

Can Materials Array Order Be Changed?

Discussion in 'Getting Started' started by Bill_Martini, Mar 11, 2018.

  1. Bill_Martini

    Bill_Martini

    Joined:
    Apr 19, 2016
    Posts:
    445
    I've made about a dozen models. All variations of each other. All have four materials assigned to the models. All models have material order correct in modeling. When I import them, some models have the material order swapped around. I've read that Unity does this on importing. How can I stop this or how can I correct the order so all models have the same material order?
     
  2. Dai-22

    Dai-22

    Joined:
    Jan 19, 2018
    Posts:
    130
    With unity imports, as far as I am aware, you manually assign them individually with drag n drop, or other models are "baked" permanently, but for first, the shader has to be selected etc, so do one first and check the look settings etc. I may be wrong, but this is my Noobie experience of .obj assets etc.

    If I'm wrong someone will say, but i think this is the way it is for now? I had the same issue with importing tree's from blender, they just turned up with nothing on them, just grey.

    What software are you importing from? Maybe look up the issue from that software to unity for a potential better solution, as you have not given much detail. Is it a coded array of materials? etc...
     
  3. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    I'm assuming you need the consistency because you want to change materials or material properties programmatically. I've feel like I've worked around this in the past by ensuring the materials are named in Blender, and then accessing the submesh by its material name. You can then swap out its material or sharedMaterial with the new one, or adjust its properties as needed.

    If you struggle with this, let me know and I'll see if I can dig up an example.
     
    Bill_Martini likes this.
  4. Dai-22

    Dai-22

    Joined:
    Jan 19, 2018
    Posts:
    130
    There is a tutorial that may be of use....maybe...

    Easy UV unwrap w/texture atlas......................cherylynne lima.........youtube. simple and effective for multiple or single colours etc...
     
  5. Bill_Martini

    Bill_Martini

    Joined:
    Apr 19, 2016
    Posts:
    445
    I'm struggling! I can't seem to find anything on this subject. Yesterday I searched for hours but only found information on single materials on an object. I can't seem to find a way to get material names from a object. The closest I've been able to do is get the array of materials and if they were consistent across all objects this wouldn't be an issue.

    You are correct in your assumption. I'm swapping albedo and normal textures for each of the four materials on each object. If I were doing this manually, I'd select the shader on the object in the inspector and select different textures for albedo and normal map. I've been accessing the material from the object. Maybe I need to get the shader and change textures through it, as I would manually. I can't find any documentation on how to do this despite many hours of going through docs and using google. Is this an uncommon or discouraged thing I'm doing?
     
  6. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    I'm absolutely swamped at work today, but I'll try to take a look at it tonight and get back to you. If I haven't responded by this time tomorrow, tag me with a reminder so I can do some digging.

    I've done a lot of UV manipulation to change a mesh's part color while keeping the same material, but the concept should be pretty similar. Keep at it, and I'll be back around to help you soon!

    Edit: This is the thread where I discussed (and received help with) doing what I described. Not sure if it'll be any use, but should be a fun read, in any case! :p
     
    Bill_Martini likes this.
  7. Bill_Martini

    Bill_Martini

    Joined:
    Apr 19, 2016
    Posts:
    445
    Thanks @Schneider21

    I got stalled on this and started working out other issues on the same project. I'll jump back to this sometime tomorrow. I did read your thread. I think I know what to do now.

    I'm having a terrible non related issue with Visual Studio and intellisense. Most time it doesn't work at all, sometimes it only knows .net syntax but not Unity's. This has me crippled for the most part. MonoDevelop just worked for me and VS has me working at a snails pace. I tried Script Inspector 3 for the second time and hate it, I can't work in a small pane like that. Seems like Unity is trying to fix something that wasn't broken, just a little behind the times.
     
  8. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    I use Visual Studio on my Mac (which is really just Xamarin Studio) and have no problems, but I have endless issues with Unity/Visual Studio on my PC. I gave up on it and started using Visual Studio Code, which is actually what I use for most of my day-job work anyway.

    Be sure to check out this article. I really do enjoy VSC and Unity together, though. Highly recommended.
     
    Bill_Martini likes this.
  9. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    This sounds just like what I used to have, from time to time, and was fixed by following the solution on this page: https://developercommunity.visualst...-new-1.html?childToView=157655#comment-157655

    I'm not sure if the "fix" is not more automatic, but you could at least try that. I haven't seen the issue, again, since doing the change.
     
    Bill_Martini likes this.
  10. Bill_Martini

    Bill_Martini

    Joined:
    Apr 19, 2016
    Posts:
    445
    I gave up on VS! I downgraded Unity and went back to Mono. I'm right in the middle of a project and it is not the time to be fiddling with new and different editors. I have a bad habit of loosing interest on projects that have gone on for more than 6 months (some less). I already have dozens of half finished projects that I tell myself 'one day I'm going to finish that', but once it's gone stale I know I'm not going back. I give up on my own terms, I'm not letting an editor force me into it.