Texture Confusion between Blender and Unity (Data Blocks??)

I’m digging into this texture import issue between Blender and Unity.

There have been a couple of topics, including:

http://forum.unity3d.com/viewtopic.php?t=14595

The issue is, and at first I tho’t this was sloppiness on my part, that in the hand off between Unity and Blender, the placement of the textures become confused. In some original Unity testing, simple objects came in with the correct textures and materials, but they were attached to unexpected surfaces.

I tried a number of import work-arounds, including fbx export/import, but this didn’t fundamentally solve the issue with the corrupted textures/materials.

In the end I started all over again, using suggestions from the forum. I started with new files and making sure the textures were already saved in the Unity directory tree. I UV textured the faces in Blender, saving the .blend file into the Unity asset tree. This seemed fine…

… until this morning.

There was a low rez object I was using to test some additional features in Unity, and it had been working fine. I could open and edit the object in Blender, update the textures in Photoshop, the pipeline seemed fine.

This morning I opened up the object in Blender, added a bit of geometry, UV textured the new piece with existing textures, adjusted a few existing UV’s, did a save…

… and there’s the hand off problem all over again.

Unity has all the correct materials. The materials are named correctly. The materials have the correct textures attached to them. The concrete material is called concrete, has concrete.jpg attached, but it’s now assigned to a face that had been using a material called hex using hex.jpg. The hex material is now being used something else.

I can force the object to display correctly in Unity by mixing and matching the textures to the materials. Put concrete.jpg on window.material and brick.jpg on glass.material, but this seems a bit ridiculous.

A brand new file works fine. There’s a point where Blender displays correctly and Unity does not. Could this be a confusion in the Blender Data Blocks? That’s a bit of an arcane area that’s dark and forboding and very scary. Haven’t touched that in detail yet?

Any other suggestions to find a work around rather than just bashing all my materials with the wrong textures now that they seem to be mis-aligned?

Any suggestion on how to prevent this from happening?

Before:

In Blender:

After, (with a copy with some forced textures):

What’s the “Outliner” view in Blender reveal? I usually look at that to verify that my materials and meshes are assigned properly.

97885--3795--$outliner_161.jpg

Not much, actually. The outliner is a window that I’ve not fully explored.

Here’s what I get:

This is with Show All chosen.

It appears that you haven’t assigned any materials in Blender. If you had, you’d see little “spheres” to the right of the mesh icon. I’m not sure if that’s causing your problem, but it might be worth investigating.

I’ll check that out.

I will admit that I am… light … on my understanding of materials. They confuse me a bit, and I very quickly end up with material, material.001, material.002, etc., that I can’t delete or control, and I can’t seem to find or control the libraries it seems to be creating. It causes such clutter! Actually, I actually don’t understand the logic or architecture that Blender is using, so I just need to sit down and find a resource re: the subject.

I discovered that when UV texturing, it seemed unnecessary to actually make a material, as Unity seemed to receive a material when I saved to project in the Unity asset tree of the project. I assumed that something was working correctly without my help. And since I knew so little, I’d decided not to monkey with it.

I’ll post more when I’ve figured out more about materials…

Thanks for the guidance.

Well, in fact I think Unity does not understand Blender Materials, all it reads is the UV mapping. AFAIK, the problem you have is not with materials, it is just that you edited the model in a way that changed the internal order of the mesh, and the same with the UVs.

Basically I have found you cannot add nor sustract geometry, bones or UV radical changes to an existing model without Unity loosing partially the links it needs and uses. And I can understand because what you are giving him is actually (internally) a different model even if you save one over the former. But otherwise, you can move, rotate or scale any pre-existing point or face, bone or UV lines without any issue.

Not that I’m an expert on the topic (maybe Eric will jump in and clear this up) but although Unity does not import Blender material information, it does use Blenders material names and their assignments to the mesh. You can control how Unity handles materials in the import settings:

97930--3797--$picture_2_214.jpg

[Crossposted w/ Big Kahuna, but it doesn’t seem to be wrong, I’m just not replying to his post.]

[I have not tested the import settings, just tried reimporting and saving as new name from Blender.]

Oddly enough, reimporting or resaving the a model maintains the confused materials problem.

I’d assumed that if Unity could interpret the materials and/or UV data correctly with the first import, that if it were reimported or saved as a new object, then Unity would be able to reinterpret it correctly as a new model. However, this is not the case. New versions maintain the error.

This leads me to believe that this has something to do with the way Blender has decided to organize it’s materials. Could this be an array/table of materials/textures and when one gets added, then no longer do you have material0 = concrete, material1 = glass, but material0 = new material, material1 = concrete, material3 = glass?? But the confusion of materials doesn’t seem this straightforward.

This could be related to Unity sharing materials and other optimizations (as yet untested by me) but, to counter my own argument, when I resaved the station object as icostation2 into the Asset tree and let Unity import it as a new object, suddenly there were new materials. Originally there were Assets/MyModels/Materials/icostation-concrete.jpg as a Unity created material on import. With the new import there was the original icostation-concrete.jpg material and a new icostation2-concrete.jpg material. Unithy didn’t seem to assign/reuse the original station materials. This implies that Unity is treating the newly saved object with a new name as a new entity in Unity, yet the materials/textures are still assigned to the wrong location. That again leads me back to Blender.

I still need to do more research into a good pipeline that’ll allow me to create objects, place them in Unity and then update and modify these objects without losing or rearranging all of the placement data.

As Big Kahuna points out, I don’t have the control I need over materials in Blender in the first place and I’m still getting up to speed with Unity, so I’m experimenting from a weak position.

(Tho’ it’s a great way to procrastinate from my javascript experiments…)

[edit]

Just for a quick experiment, I reimported the object using the different material/texture settings and it made no difference to the placement confusion.

This could easily be because I only have one material per texture, but as you can see, I didn’t make the materials, so I wouldn’t know.

[/edit]