Jump to content

Problems in unity


Recommended Posts

Hi there, all of a sudden I can't import my blender files properly into Unity. Was a while I did a part and I've got Unity version 4.5.2f1 now. Anyways, here's what I do.

  • Create Blender file of model, a detailed mesh with material, image and UV mapped with an applied texture and a normal map for importing into Unity. A less detailed mesh with just 40 or so faces to be used as the collision mesh. Apply material to the collision mesh then hide it by clicking the "eye" icon next to it. The meshes are next to each other in the hierarchy. Perhaps the collision mesh should be under the detailed one? Anyways, export to .obj.
  • Load up unity after having placed texture, texture_NRM, .obj and .mtl file in correct asset folder.
  • Create new scene, new empty Gameobject and add KSP Parttools.
  • Place default mesh under the Parttools in the hierarchy.

This is where I'm encountering problems. First of all it say's my mesh doesn't have any normals, so it tries to recalculate normals without doing it. I manually changed the import option to recalculate normals. Another problem is that I get three materials although I only have two applied in blender, one for the detailed mesh and one for the collision mesh. The third material is called "no name" and seems to affect the collision mesh but I am not sure. After fiddling about I exported it to .mu, wrote a .cfg and loaded the game. The part loaded, but it wasn't the detailed and textured mesh that did but the collision mesh with just a plane white texture (placeholder I guess). So, wtf is going on with Unity? Can't for the life of me figure out what I'm doing wrong. Any help would be greatly appreciated!

Link to comment
Share on other sites

you don't need the .mtl file in Unity.

once you import the OBJ, texture and texture_NRM, assign a KSP/Diffuse+Bump shader to your mesh, then assign the textures to the respective slots in the shader.

apply Mesh collider to the collision mesh, check "Convex"; then remove the Mesh Filter and Mesh Renderer Components. you should see a green outline of your collision mesh around your textured mesh at this point.

export and follow the rest of your steps to load the part in Editor.

Link to comment
Share on other sites

you don't need the .mtl file in Unity.

once you import the OBJ, texture and texture_NRM, assign a KSP/Diffuse+Bump shader to your mesh, then assign the textures to the respective slots in the shader.

apply Mesh collider to the collision mesh, check "Convex"; then remove the Mesh Filter and Mesh Renderer Components. you should see a green outline of your collision mesh around your textured mesh at this point.

export and follow the rest of your steps to load the part in Editor.

Okay I've reinstalled Blender and am now skipping adding the .mtl file. But now I only get one material imported although I have material and texture (with "none" selected in Blender on both) on the collision mesh and the detailed mesh. And the collision mesh and detailed mesh are fused together when imported into Unity. The area for Mesh Collider and Mesh Renderer are greyed out. It still also says my mesh doesn't have any normals, what gives? Of course it has normals, have tried flipping the faces in Blender as well as recalculating them.

- - - Updated - - -

Except when Blender crashes when Unity tries to use it. I've had that happen with Blender 2.71.

Yeah the same thing happens for me. Glad I'm not the only one with that issue at least.

Link to comment
Share on other sites

Unity seems to automatically assign a material to everything, afaik you dont need a material for the collider as you want that to be invisible, to add a material in unity is no problem, just import one from another project and assign it to the parts you want it applied to, I get nonsense like this all the time and thought it was just me..

Link to comment
Share on other sites

Unity seems to automatically assign a material to everything, afaik you dont need a material for the collider as you want that to be invisible, to add a material in unity is no problem, just import one from another project and assign it to the parts you want it applied to, I get nonsense like this all the time and thought it was just me..

Tried it without a material now and had it hidden. It still merges/fuses with the detailed mesh in Unity when importing the .obj. Will try to reinstall Blender 2.6 and see if it works.

Link to comment
Share on other sites

Tried it without a material now and had it hidden. It still merges/fuses with the detailed mesh in Unity when importing the .obj. Will try to reinstall Blender 2.6 and see if it works.

Well Blender 2.6 didn't work and I don't want to spend too much time on that version since it lacks some things available in 2.71 I deem absolutely necessary. So the problem is that the collision mesh in blender merges with the detailed "normal" mesh when importing into Unity instead of remaining split into two meshes. So I cannot untick Mesh Renderer so that the collision mesh is invisible in game.

Link to comment
Share on other sites

did you export normals in the OBJ? make sure "Write Normals" box is checked, it's off by default. Uncheck "Write Materials", should stop exporting the .mtl. OBJ was originally a Lightwave format, and mtl is Lightwave's native material. it's good practice to collapse your modifier stack, reset transform/pivot and reset scale before exporting. I do it everytime.

Unity assigns default shader to everything if you uncheck "Import Materials" in import settings. it's a simple white diffuse shader and can't be edited. You have to assign a new shader you created before you can make any edits to the shader settings.

If your collision mesh is visible in game, it's because you didn't remove the "Mesh Filter" and "Mesh Renderer" component from the collision object in Unity.

Link to comment
Share on other sites

Maybe I'm being an idiot here, but can't you just import the two meshes separately then place them under the same gameobject, apply colliders to your simpler mesh then remove its mesh renderer?
did you export normals in the OBJ? make sure "Write Normals" box is checked, it's off by default. Uncheck "Write Materials", should stop exporting the .mtl. OBJ was originally a Lightwave format, and mtl is Lightwave's native material. it's good practice to collapse your modifier stack, reset transform/pivot and reset scale before exporting. I do it everytime.

Unity assigns default shader to everything if you uncheck "Import Materials" in import settings. it's a simple white diffuse shader and can't be edited. You have to assign a new shader you created before you can make any edits to the shader settings.

If your collision mesh is visible in game, it's because you didn't remove the "Mesh Filter" and "Mesh Renderer" component from the collision object in Unity.

I combined both of your suggestions and it works now! Thank you so very much, have spent 4 hours bashing my head in. Anyways, I split up my exports into two as AlphaAsh suggested. Then I used your export settings nli2work. So I exported one .obj for the collision mesh and one for the detailed mesh (both had materials and texture "none" applied). Then I imported them into Unity's asset folder and used the detailed mesh as child in the gameobject hierarchy. Under Mesh Collider I pressed the circle to the right of Mesh (at the bottom) and selected the collision mesh .obj. That worked liked a charm, and tried it out in game now and normal maps and everything was applied.

Then I tried one export with the collision mesh as a child in the hierarchy in Blender with it invisible. Then one time with it at the same level in the hierarchy in Blender and invisible. Neither of the attempts worked, the two meshes were still fused when imported into Unity. Don't know what's wrong with that. Would love for that method to work since it's slightly less work but oh well. Just happy it works now! Thanks once again!

Link to comment
Share on other sites

glad to hear you got it working. exporting bits separately is no problem for unity, everything is a GameObject, just with different functions tacked on. You can even combine different meshes for new parts without any modeling at all. Visibility settings in 3D apps don't apply in Unity, if you turn something invisible and use "Export Selected" option instead of "Export", there's a chance it doesn't get exported at all because you can't select invisible objects in the viewport.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...