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

Material applying inconsistently to imported object

Discussion in 'Editor & General Support' started by Altissimus, Jun 8, 2019.

  1. Altissimus

    Altissimus

    Joined:
    May 11, 2015
    Posts:
    49
    Hi,

    Video shows what happens when I apply various materials to an imported object (on the left) and a regular sphere (on the right). All is fine and dandy until we get to a material with some textures. It appears to apply just fine, according to the inspector (as the video shows), but the visual effect is quite different.

    Any clues as to why this would be please?

    Thanks,

    A

     
    aparajithsairam likes this.
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    Did you UV unwrap the object on the left? What program did you model it in? Usually when I assign materials to an imported FBX model, I do so in the Materials tab of the inspector when the model asset (not the one in the scene) is selected. For example:

    upload_2019-6-8_21-17-48.png

    What does that look like for your model?
     
    aparajithsairam likes this.
  3. Altissimus

    Altissimus

    Joined:
    May 11, 2015
    Posts:
    49
    Hi,

    No, I didn't unwrap it because you don't need to to apply materials. It was modelled in Blender.
    Yes, I did try assigning it in the object import tab. Mine looks the same as yours. Have also tried this without generating materials and using Unity's default material instead. Have also tried applying this material directly here - doesn't work either.

    Any ideas please?
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    If you modelled it in Blender, you need to UV unwrap it. Blender won't do that for you (unless you chose to UV unwrap when creating the sphere you have here, but in general UV unwrapping occurs after modelling.)

    For example, here are a couple of spheres created in Blender, to which I've applied the kind-of default Color Grid material, but I haven't unwrapped them. Notice the material looks like a solid color:

    upload_2019-6-9_11-29-55.png

    Now the same spheres once they've been UV unwrapped:

    upload_2019-6-9_11-30-34.png

    So unless I'm missing something, make sure your models are unwrapped. What does the model look like in Blender if you assign a texture to its material?

    upload_2019-6-9_11-32-1.png
     
  5. Altissimus

    Altissimus

    Joined:
    May 11, 2015
    Posts:
    49
    Hi,

    I'm not unwrapping them because I'm assigining multiple materials in Blender and exporting the lot. As you can see in the video I can apply other materials to my object just fine (and as can be seen in the video it only assigns to the part of the object that applies to that material). However, it's only the last material that isn't applying properly.

    So, what difference does UV unwrapping make to this workstream? TBH I am new to this and can't find a single (consistent) tutorial online or anywhere that actually explains the incredibly complex relationship between Blender and Unity for this. Having spent literally hours upon hours on this, I discovered that UV unwrapping is redundant if you create multiple materials in Blender. You can then apply the shaders directly in Unity to those material locales.

    Are you saying that I can't apply textures without a UV map? Can you please explain to me how to effectively export from Blender to Unity with a UV map in such a way as the end result can be dynamically lit (i.e. not baked at any point)?

    Many thanks!

    A

    Edited to add - as I’m also applying four different materials does that mean I need 4 different UV maps? I have previously used multiple maps for multiple mats in Blender, but don’t know how to shift multiple UV maps to Unity
     
    Last edited: Jun 9, 2019
  6. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    Okay, I think I fully understand the issue you're facing. In short, what you're doing with using multiple materials is fine, and it should work fine for materials that are a single solid color. But for materials with a texture on it (like the blue one in your video) you also need to UV unwrap the object. The good news is that it's often pretty simple to UV unwrap objects in blender, though getting it exactly the way you want isn't always easy.

    UV mapping is required for any materials with non-uniform textures. The UV map is the thing that tells the rendering software (blender or Unity in this case) which pixel from the texture gets placed onto which part of the model. Unity can't tell, on its own, how the texture should "wrap" around your object. So you need to tell it how to do this with a UV map. The UV map basically says, for any given point on your model, which pixel from the texture it should use. UV unwrapping can be complex, and it will definitely take you some time to understand it completely. But if you're just getting started, there are some simple things you can do.

    The simplest thing, for a sphere, is to create it already unwrapped. When you add a UV Sphere, there's an option to generate UVs:

    upload_2019-6-9_16-18-16.png

    Check that, and Blender will create a decent UV map for you:

    upload_2019-6-9_16-18-39.png

    Now, if you assign a texture to the material, it will probably look pretty good:

    upload_2019-6-9_16-19-26.png


    For other objects, especially those that aren't primitive geometric shapes, Blender's Smart UV Project is the easiest thing. With the faces selected, press "u" to get the UV mapping menu, and choose Smart UV Project.

    upload_2019-6-9_16-23-36.png

    For a sphere it won't look great, but for complex shapes it's pretty easy.

    Things get significantly more complex if the texture has a specific orientation, such as wood panels, which you want to line up with the object. But maybe that's enough to get you started.

    I'd look into basic UV unwrapping in blender to understand the concept.
     
  7. Altissimus

    Altissimus

    Joined:
    May 11, 2015
    Posts:
    49
    "UV mapping is required for any materials with non-uniform textures."

    ...ahh, I didn't know that. And by the way, you've already been way more helpful than most of the tutorials I could find. But now we're just getting into the area I'm not sure about.

    So I'm happy with UV unwrapping. Done it enough times while I've struggled to get this shizzit to work over the past few weeks. Now, let's say I have an object that I want to apply 4 distinct colours to, and in Unity I want one of them to have a texture and I want another of them to be able to have active emissions (i.e. light). How best to go about this?

    Like:
    Option 1) 4 materials, one UV map; in Blender apply different colour to all 4, and in Unity apply emission to one, texture to another.
    Option 2) 3 materials, one UV map; one with the emission in Unity, one with texture in Unity, one with all the colours from blender
    Option 3) 4 materials, 4 different UV maps?
    Option 4) ...? ..?

    (I'm not saying Option 1 or 2 would work here. Examples.)

    So, let's say for argument's sake that I end up with a single UV map with 4 materials and a texture. How do I get that info into Unity in a way that doesn't melt either a) my computer, or b) my brain?

    This is basically what I've done up until now, incidentally (imported object, check; multiple materials, check; texture, check; UV mapping, check) - I just haven't done it all at once. Closest I've got is object + multiple materials + non-functioning texture. How do I bring in the UV map? Where do I put that in the shader? Does it just need to sit in the asset folder and magically be referenced? I doubt it.

    Thanks,
    A
     
  8. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    For the most part, you'l only be dealing with a single UV map ever, regardless of the number of materials. It's possible for an object to have more than one UV map, but that's more advanced, and not something I've ever needed yet for generally realistic PBR-like objects.

    Option 1 sounds the most reasonable to me, for your use-case. Each material can have independent color and emission characteristics. It's up to you whether any given material is a solid color, or uses textures. That's all fine. This should be pretty simple in Unity. In Unity, you'd create the four corresponding materials, and assign then to the FBX in the inspector on the Materials tab, like we already talked about. Then make those materials look however you want. Having several materials on a single object/model is very common, so no specific performance concerns there.

    Once you unwrap the object in Blender, the UV map will just be part of the exported FBX. You won't need to do anything beyond unwrapping it. No need to do anything with the shader; it already knows about UV maps, and it'll just do everything right. And just for example, if you go into Blender right now, add a UV Sphere, make sure to check that "Generate UVs" box, and then import it into Unity, you'll see that your textured material will probably look just fine on the model.

    This approach should be fine for now, and may be all you ever want to relatively simple objects. I'd say the next step after this is to use software like Substance Painter (or some other software that allows you to easily draw textures on models) and export the results as individual textures. For example, in your case, despite wanting four different materials on it, you could probably do that with a single material. It's possible Blender allows you to do this, I'm not sure. (I use Substance Painter, so that's the only workflow I know. I'm not suggesting you use it for something this simple, but you might find it interesting to watch a "getting started" type of video on it to get an idea of what it's capable of.)
     
  9. Altissimus

    Altissimus

    Joined:
    May 11, 2015
    Posts:
    49
    Thanks again. Good thread :) Substance Painter looks awesome, but out of my budget.